diff --git a/src/matrix/Session.js b/src/matrix/Session.js index 138fb6e5..c2b85215 100644 --- a/src/matrix/Session.js +++ b/src/matrix/Session.js @@ -648,6 +648,25 @@ export class Session { } return observable; } + + loadArchivedRoom(roomId, log = null) { + return this._platform.logger.wrapOrRun(log, "loadArchivedRoom", async log => { + log.set("id", roomId); + const txn = await this._storage.readTxn([ + this._storage.storeNames.archivedRoomSummary, + this._storage.storeNames.roomMembers, + ]); + const summary = await txn.archivedRoomSummary.get(roomId); + if (summary) { + // TODO: should we really be using a Room here? + // Or rather an ArchivedRoom that shares a common base class with Room? + // That will make the Room code harder to read though ... + const room = this.createRoom(roomId); + await room.load(summary, txn, log); + return room; + } + }); + } } export function tests() { diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index 375f98c0..62431ef6 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -442,7 +442,10 @@ export class Room extends EventEmitter { const changes = await this._heroes.calculateChanges(this._summary.data.heroes, [], txn); this._heroes.applyChanges(changes, this._summary.data); } - return this._syncWriter.load(txn, log); + // don't load sync writer for archived room + if (this.membership !== "leave") { + return this._syncWriter.load(txn, log); + } } catch (err) { throw new WrappedError(`Could not load room ${this._roomId}`, err); } diff --git a/src/matrix/storage/idb/stores/RoomSummaryStore.js b/src/matrix/storage/idb/stores/RoomSummaryStore.js index f4ae4431..426a01bb 100644 --- a/src/matrix/storage/idb/stores/RoomSummaryStore.js +++ b/src/matrix/storage/idb/stores/RoomSummaryStore.js @@ -42,6 +42,10 @@ export class RoomSummaryStore { return this._summaryStore.put(summary); } + get(roomId) { + return this._summaryStore.get(roomId); + } + async has(roomId) { const fetchedKey = await this._summaryStore.getKey(roomId); return roomId === fetchedKey;