From f6957278c37a64c6d9b097acbf8bff90240d21a2 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 5 May 2021 17:03:22 +0200 Subject: [PATCH] write and remove archived summary when leaving/rejoining --- src/matrix/room/Room.js | 12 ++++++++++-- src/matrix/room/RoomSummary.js | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) 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;