From 00d8f81bddcfa301521a0ee7311c56da287ddab3 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 5 May 2021 19:04:26 +0200 Subject: [PATCH] clear all room state before rejoining room --- src/matrix/room/Room.js | 3 +++ src/matrix/storage/idb/stores/RoomStateStore.js | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index 61e3ff2e..00a97bcf 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -251,6 +251,9 @@ export class Room extends EventEmitter { log.set("id", this.id); const isRejoin = summaryChanges.membership === "join" && this.membership !== "join"; if (isRejoin) { + // remove all room state before calling syncWriter, + // so no old state sticks around + txn.roomState.removeAllForRoom(this.id); this._summary.tryRemoveArchive(txn); } const {entries: newEntries, newLiveKey, memberChanges} = diff --git a/src/matrix/storage/idb/stores/RoomStateStore.js b/src/matrix/storage/idb/stores/RoomStateStore.js index 0cec87bc..4b5ea118 100644 --- a/src/matrix/storage/idb/stores/RoomStateStore.js +++ b/src/matrix/storage/idb/stores/RoomStateStore.js @@ -14,17 +14,19 @@ See the License for the specific language governing permissions and limitations under the License. */ +const MAX_UNICODE = "\u{10FFFF}"; + export class RoomStateStore { constructor(idbStore) { this._roomStateStore = idbStore; } async getAllForType(type) { - + throw new Error("unimplemented"); } async get(type, stateKey) { - + throw new Error("unimplemented"); } async set(roomId, event) { @@ -32,4 +34,11 @@ export class RoomStateStore { const entry = {roomId, event, key}; return this._roomStateStore.put(entry); } + + removeAllForRoom(roomId) { + // exclude both keys as they are theoretical min and max, + // but we should't have a match for just the room id, or room id with max + const range = IDBKeyRange.bound(roomId, `${roomId}|${MAX_UNICODE}`, true, true); + this._roomStateStore.delete(range); + } }