Control the race condition when swapping between rooms
This commit is contained in:
parent
8325c5934d
commit
ee85f73ad1
1 changed files with 21 additions and 15 deletions
|
@ -36,7 +36,7 @@ Please see LICENSE files in the repository root for full details.
|
||||||
* list ops)
|
* list ops)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { MatrixClient, EventType } from "matrix-js-sdk/src/matrix";
|
import { MatrixClient, EventType, ClientEvent, Room } from "matrix-js-sdk/src/matrix";
|
||||||
import {
|
import {
|
||||||
MSC3575Filter,
|
MSC3575Filter,
|
||||||
MSC3575List,
|
MSC3575List,
|
||||||
|
@ -232,29 +232,35 @@ export class SlidingSyncManager {
|
||||||
subscriptions.delete(roomId);
|
subscriptions.delete(roomId);
|
||||||
}
|
}
|
||||||
const room = this.client?.getRoom(roomId);
|
const room = this.client?.getRoom(roomId);
|
||||||
let shouldLazyLoad = !this.client?.isRoomEncrypted(roomId);
|
// default to safety: request all state if we can't work it out. This can happen if you
|
||||||
if (!room) {
|
// refresh the app whilst viewing a room: we call setRoomVisible before we know anything
|
||||||
// default to safety: request all state if we can't work it out. This can happen if you
|
// about the room.
|
||||||
// refresh the app whilst viewing a room: we call setRoomVisible before we know anything
|
let shouldLazyLoad = false;
|
||||||
// about the room.
|
if (room) {
|
||||||
shouldLazyLoad = false;
|
// do not lazy load encrypted rooms as we need the entire member list.
|
||||||
|
shouldLazyLoad = !room.hasEncryptionStateEvent()
|
||||||
}
|
}
|
||||||
logger.log("SlidingSync setRoomVisible:", roomId, visible, "shouldLazyLoad:", shouldLazyLoad);
|
logger.log("SlidingSync setRoomVisible:", roomId, visible, "shouldLazyLoad:", shouldLazyLoad);
|
||||||
if (shouldLazyLoad) {
|
if (shouldLazyLoad) {
|
||||||
// lazy load this room
|
// lazy load this room
|
||||||
this.slidingSync!.useCustomSubscription(roomId, UNENCRYPTED_SUBSCRIPTION_NAME);
|
this.slidingSync!.useCustomSubscription(roomId, UNENCRYPTED_SUBSCRIPTION_NAME);
|
||||||
}
|
}
|
||||||
const p = this.slidingSync!.modifyRoomSubscriptions(subscriptions);
|
this.slidingSync!.modifyRoomSubscriptions(subscriptions);
|
||||||
if (room) {
|
if (room) {
|
||||||
return roomId; // we have data already for this room, show immediately e.g it's in a list
|
return roomId; // we have data already for this room, show immediately e.g it's in a list
|
||||||
}
|
}
|
||||||
try {
|
// wait until we know about this room. This may take a little while.
|
||||||
// wait until the next sync before returning as RoomView may need to know the current state
|
return new Promise((resolve) => {
|
||||||
await p;
|
logger.log(`SlidingSync setRoomVisible room ${roomId} not found, waiting for ClientEvent.Room`);
|
||||||
} catch (err) {
|
const waitForRoom = (r: Room) => {
|
||||||
logger.warn("SlidingSync setRoomVisible:", roomId, visible, "failed to confirm transaction");
|
if (r.roomId === roomId) {
|
||||||
}
|
this.client?.off(ClientEvent.Room, waitForRoom);
|
||||||
return roomId;
|
logger.log(`SlidingSync room ${roomId} found, resolving setRoomVisible`);
|
||||||
|
resolve(roomId);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.client?.on(ClientEvent.Room, waitForRoom);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue