diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index d7a2c47b..a4dcff0a 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -250,6 +250,9 @@ export class Room extends EventEmitter { async writeSync(roomResponse, isInitialSync, {summaryChanges, decryptChanges, roomEncryption, retryEntries}, txn, log) { log.set("id", this.id); const isRejoin = summaryChanges.membership === "join" && this._summary.data.membership === "leave"; + if (isRejoin) { + this._summary.tryRemoveArchive(txn); + } const {entries: newEntries, newLiveKey, memberChanges} = await log.wrap("syncWriter", log => this._syncWriter.writeSync(roomResponse, isRejoin, txn, log), log.level.Detail); let allEntries = newEntries; @@ -276,8 +279,13 @@ export class Room extends EventEmitter { // also apply (decrypted) timeline entries to the summary changes summaryChanges = summaryChanges.applyTimelineEntries( allEntries, isInitialSync, !this._isTimelineOpen, this._user.id); - // write summary changes, and unset if nothing was actually changed - summaryChanges = this._summary.writeData(summaryChanges, txn); + // only archive a room if we had previously joined it + if (summaryChanges.membership === "leave" && this.membership === "join") { + summaryChanges = this._summary.removeAndWriteArchive(summaryChanges, txn); + } else { + // write summary changes, and unset if nothing was actually changed + summaryChanges = this._summary.writeData(summaryChanges, txn); + } if (summaryChanges) { log.set("summaryChanges", summaryChanges.diff(this._summary.data)); } diff --git a/src/matrix/room/RoomSummary.js b/src/matrix/room/RoomSummary.js index 5cdc24a6..86927e03 100644 --- a/src/matrix/room/RoomSummary.js +++ b/src/matrix/room/RoomSummary.js @@ -302,6 +302,20 @@ export class RoomSummary { } } + /** move summary to archived store when leaving the room */ + removeAndWriteArchive(data, txn) { + txn.roomSummary.remove(data.roomId); + if (data !== this._data) { + txn.archivedRoomSummary.set(data.serialize()); + return data; + } + } + + /** delete archived summary when rejoining the room */ + tryRemoveArchive(txn) { + txn.archivedRoomSummary.remove(this._data.roomId); + } + async writeAndApplyData(data, storage) { if (data === this._data) { return false;