allow loading an archived room

This commit is contained in:
Bruno Windels 2021-05-07 13:10:10 +02:00
parent 1b83ae7d8a
commit 6bb8e2fa43
3 changed files with 27 additions and 1 deletions

View File

@ -648,6 +648,25 @@ export class Session {
} }
return observable; 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() { export function tests() {

View File

@ -442,7 +442,10 @@ export class Room extends EventEmitter {
const changes = await this._heroes.calculateChanges(this._summary.data.heroes, [], txn); const changes = await this._heroes.calculateChanges(this._summary.data.heroes, [], txn);
this._heroes.applyChanges(changes, this._summary.data); 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) { } catch (err) {
throw new WrappedError(`Could not load room ${this._roomId}`, err); throw new WrappedError(`Could not load room ${this._roomId}`, err);
} }

View File

@ -42,6 +42,10 @@ export class RoomSummaryStore {
return this._summaryStore.put(summary); return this._summaryStore.put(summary);
} }
get(roomId) {
return this._summaryStore.get(roomId);
}
async has(roomId) { async has(roomId) {
const fetchedKey = await this._summaryStore.getKey(roomId); const fetchedKey = await this._summaryStore.getKey(roomId);
return roomId === fetchedKey; return roomId === fetchedKey;