From 2855166239851f9141c59a7b34be35c42edb7e2e Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 11 Sep 2020 16:48:04 +0200 Subject: [PATCH] migrate encryption flag so old sessions dont send unencrypted events --- src/matrix/storage/idb/schema.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/matrix/storage/idb/schema.js b/src/matrix/storage/idb/schema.js index 809f6729..b78c117b 100644 --- a/src/matrix/storage/idb/schema.js +++ b/src/matrix/storage/idb/schema.js @@ -9,7 +9,8 @@ export const schema = [ createInitialStores, createMemberStore, migrateSession, - createE2EEStores + createE2EEStores, + migrateEncryptionFlag ]; // TODO: how to deal with git merge conflicts of this array? @@ -77,3 +78,22 @@ function createE2EEStores(db) { const operations = db.createObjectStore("operations", {keyPath: "id"}); operations.createIndex("byTypeAndScope", "typeScopeKey", {unique: false}); } + +// v5 +async function migrateEncryptionFlag(db, txn) { + // migrate room summary isEncrypted -> encryption prop + const roomSummary = txn.objectStore("roomSummary"); + const roomState = txn.objectStore("roomState"); + const summaries = []; + await iterateCursor(roomSummary.openCursor(), summary => { + summaries.push(summary); + }); + for (const summary of summaries) { + const encryptionEntry = await reqAsPromise(roomState.get(`${summary.roomId}|m.room.encryption|`)); + if (encryptionEntry) { + summary.encryption = encryptionEntry?.event?.content; + delete summary.isEncrypted; + roomSummary.put(summary); + } + } +}