forked from element-hq/hydrogen-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'peeking_with_guest_login' into integrations
- Loading branch information
Showing
13 changed files
with
396 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import {RoomViewModel} from "./RoomViewModel"; | ||
|
||
export class WorldReadableRoomViewModel extends RoomViewModel { | ||
constructor(options) { | ||
options.room.isWorldReadable = true; | ||
super(options); | ||
const {room, session, guestJoinAllowed} = options; | ||
this._room = room; | ||
this._session = session; | ||
this._error = null; | ||
this._busy = false; | ||
this._guestJoinAllowed = typeof guestJoinAllowed !== 'undefined' && guestJoinAllowed; | ||
|
||
// join allowed for the current user/session? | ||
this._joinAllowed = false; | ||
this._session.isGuest().then((isGuest) => { | ||
this._joinAllowed = isGuest ? this._guestJoinAllowed : true; | ||
this.emitChange('joinAllowed'); | ||
}); | ||
} | ||
|
||
get kind() { | ||
return "preview"; | ||
} | ||
|
||
get busy() { | ||
return this._busy; | ||
} | ||
|
||
get joinAllowed() { | ||
return this._joinAllowed; | ||
} | ||
|
||
async join() { | ||
this._busy = true; | ||
this.emitChange("busy"); | ||
try { | ||
const roomId = await this._session.joinRoom(this._room.id); | ||
// navigate to roomId if we were at the alias | ||
// so we're subscribed to the right room status | ||
// and we'll switch to the room view model once | ||
// the join is synced | ||
this.navigation.push("room", roomId); | ||
// keep busy on true while waiting for the join to sync | ||
} catch (err) { | ||
this._error = err; | ||
this._busy = false; | ||
this.emitChange("error"); | ||
} | ||
} | ||
|
||
login() { | ||
this.navigation.push("login"); | ||
} | ||
|
||
dispose() { | ||
super.dispose(); | ||
|
||
// if joining the room, _busy would be true and in that case don't delete records | ||
if (!this._busy) { | ||
void this._session.deleteWorldReadableRoomData(this._room.id); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.