allow loading an archived room
This commit is contained in:
parent
1b83ae7d8a
commit
6bb8e2fa43
3 changed files with 27 additions and 1 deletions
|
@ -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() {
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
// don't load sync writer for archived room
|
||||||
|
if (this.membership !== "leave") {
|
||||||
return this._syncWriter.load(txn, log);
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Reference in a new issue