mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
Wait for room to come through sync
This commit is contained in:
parent
9a6d15a72b
commit
de57e07982
@ -21,6 +21,7 @@ import type {GroupCall} from "../../../matrix/calls/group/GroupCall";
|
|||||||
import type {Room} from "../../../matrix/room/Room.js";
|
import type {Room} from "../../../matrix/room/Room.js";
|
||||||
import type {Session} from "../../../matrix/Session.js";
|
import type {Session} from "../../../matrix/Session.js";
|
||||||
import type {SegmentType} from "../../navigation";
|
import type {SegmentType} from "../../navigation";
|
||||||
|
import { RoomStatus } from "../../../lib";
|
||||||
|
|
||||||
type Options = {
|
type Options = {
|
||||||
session: Session;
|
session: Session;
|
||||||
@ -36,12 +37,9 @@ export class ToastCollectionViewModel extends ViewModel<SegmentType, Options> {
|
|||||||
this.track(callsObservableMap.subscribe(this));
|
this.track(callsObservableMap.subscribe(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
onAdd(_, call: GroupCall) {
|
async onAdd(_, call: GroupCall) {
|
||||||
if (this._shouldShowNotification(call)) {
|
if (this._shouldShowNotification(call)) {
|
||||||
const room = this._findRoomForCall(call);
|
const room = await this._findRoomForCall(call);
|
||||||
if (!room) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const dismiss = () => {
|
const dismiss = () => {
|
||||||
const idx = this.toastViewModels.array.findIndex(vm => vm.call === call);
|
const idx = this.toastViewModels.array.findIndex(vm => vm.call === call);
|
||||||
if (idx !== -1) {
|
if (idx !== -1) {
|
||||||
@ -74,10 +72,16 @@ export class ToastCollectionViewModel extends ViewModel<SegmentType, Options> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _findRoomForCall(call: GroupCall): Room {
|
private async _findRoomForCall(call: GroupCall): Promise<Room> {
|
||||||
const id = call.roomId;
|
const id = call.roomId;
|
||||||
const rooms = this.getOption("session").rooms;
|
const session = this.getOption("session");
|
||||||
return rooms.get(id);
|
const rooms = session.rooms;
|
||||||
|
// Make sure that we know of this room,
|
||||||
|
// otherwise wait for it to come through sync
|
||||||
|
const observable = await session.observeRoomStatus(id);
|
||||||
|
await observable.waitFor(s => s === RoomStatus.Joined).promise;
|
||||||
|
const room = rooms.get(id);
|
||||||
|
return room;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _shouldShowNotification(call: GroupCall): boolean {
|
private _shouldShowNotification(call: GroupCall): boolean {
|
||||||
|
@ -132,6 +132,7 @@ export class Session {
|
|||||||
this._createRoomEncryption = this._createRoomEncryption.bind(this);
|
this._createRoomEncryption = this._createRoomEncryption.bind(this);
|
||||||
this._forgetArchivedRoom = this._forgetArchivedRoom.bind(this);
|
this._forgetArchivedRoom = this._forgetArchivedRoom.bind(this);
|
||||||
this.needsKeyBackup = new ObservableValue(false);
|
this.needsKeyBackup = new ObservableValue(false);
|
||||||
|
this._pendingObserveCalls = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
get fingerprintKey() {
|
get fingerprintKey() {
|
||||||
@ -776,7 +777,7 @@ export class Session {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
applyRoomCollectionChangesAfterSync(inviteStates, roomStates, archivedRoomStates, log) {
|
async applyRoomCollectionChangesAfterSync(inviteStates, roomStates, archivedRoomStates, log) {
|
||||||
// update the collections after sync
|
// update the collections after sync
|
||||||
for (const rs of roomStates) {
|
for (const rs of roomStates) {
|
||||||
if (rs.shouldAdd) {
|
if (rs.shouldAdd) {
|
||||||
@ -796,6 +797,8 @@ export class Session {
|
|||||||
// now all the collections are updated, update the room status
|
// now all the collections are updated, update the room status
|
||||||
// so any listeners to the status will find the collections
|
// so any listeners to the status will find the collections
|
||||||
// completely up to date
|
// completely up to date
|
||||||
|
await Promise.all(this._pendingObserveCalls);
|
||||||
|
this._pendingObserveCalls = [];
|
||||||
if (this._observedRoomStatus.size !== 0) {
|
if (this._observedRoomStatus.size !== 0) {
|
||||||
for (const ars of archivedRoomStates) {
|
for (const ars of archivedRoomStates) {
|
||||||
if (ars.shouldAdd) {
|
if (ars.shouldAdd) {
|
||||||
@ -938,6 +941,7 @@ export class Session {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async observeRoomStatus(roomId) {
|
async observeRoomStatus(roomId) {
|
||||||
|
const op = async () => {
|
||||||
let observable = this._observedRoomStatus.get(roomId);
|
let observable = this._observedRoomStatus.get(roomId);
|
||||||
if (!observable) {
|
if (!observable) {
|
||||||
const status = await this.getRoomStatus(roomId);
|
const status = await this.getRoomStatus(roomId);
|
||||||
@ -949,6 +953,10 @@ export class Session {
|
|||||||
}
|
}
|
||||||
return observable;
|
return observable;
|
||||||
}
|
}
|
||||||
|
const promise = op();
|
||||||
|
this._pendingObserveCalls.push(promise);
|
||||||
|
return await promise;
|
||||||
|
}
|
||||||
|
|
||||||
observeRoomState(roomStateHandler) {
|
observeRoomState(roomStateHandler) {
|
||||||
return this._roomStateHandler.subscribe(roomStateHandler);
|
return this._roomStateHandler.subscribe(roomStateHandler);
|
||||||
|
Loading…
Reference in New Issue
Block a user