diff --git a/src/matrix/Session.js b/src/matrix/Session.js index 527b7e6c..3cf1df65 100644 --- a/src/matrix/Session.js +++ b/src/matrix/Session.js @@ -671,6 +671,23 @@ export class Session { return observable; } + /** + Creates an empty (summary isn't loaded) the archived room if it isn't + loaded already, assuming sync will either remove it (when rejoining) or + write a full summary adopting it from the joined room when leaving + + @internal + */ + createOrGetArchivedRoomForSync(roomId) { + let archivedRoom = this._activeArchivedRooms.get(roomId); + if (archivedRoom) { + archivedRoom.retain(); + } else { + archivedRoom = this._createArchivedRoom(roomId); + } + return archivedRoom; + } + loadArchivedRoom(roomId, log = null) { return this._platform.logger.wrapOrRun(log, "loadArchivedRoom", async log => { log.set("id", roomId); diff --git a/src/matrix/Sync.js b/src/matrix/Sync.js index ac0da4b2..62bb67bd 100644 --- a/src/matrix/Sync.js +++ b/src/matrix/Sync.js @@ -410,12 +410,12 @@ export class Sync { // when adding a joined room during incremental sync, // always create the archived room to write the removal // of the archived summary - archivedRoom = await this._session.loadArchivedRoom(roomId, log); + archivedRoom = this._session.createOrGetArchivedRoomForSync(roomId); } else if (membership === "leave") { if (roomState) { // we still have a roomState, so we just left it // in this case, create a new archivedRoom - archivedRoom = await this._session.loadArchivedRoom(roomId, log); + archivedRoom = this._session.createOrGetArchivedRoomForSync(roomId); } else { // this is an update of an already left room, restore // it from storage first, so we can increment it.