From 2e3616e05dc082bf65885caf7e5b0d5cb4cb23b6 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 1 Feb 2022 12:31:10 +0100 Subject: [PATCH] call cursor.update during backup field migration, needs new version --- src/matrix/storage/idb/schema.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/matrix/storage/idb/schema.ts b/src/matrix/storage/idb/schema.ts index fa4374cd..7819130e 100644 --- a/src/matrix/storage/idb/schema.ts +++ b/src/matrix/storage/idb/schema.ts @@ -33,7 +33,8 @@ export const schema: MigrationFunc[] = [ changeSSSSKeyPrefix, backupAndRestoreE2EEAccountToLocalStorage, clearAllStores, - addInboundSessionBackupIndex + addInboundSessionBackupIndex, + migrateBackupStatus ]; // TODO: how to deal with git merge conflicts of this array? @@ -280,6 +281,13 @@ async function clearAllStores(db: IDBDatabase, txn: IDBTransaction) { // v15 add backup index to inboundGroupSessions async function addInboundSessionBackupIndex(db: IDBDatabase, txn: IDBTransaction, localStorage: IDOMStorage, log: ILogItem): Promise { + const inboundGroupSessions = txn.objectStore("inboundGroupSessions"); + inboundGroupSessions.createIndex("byBackup", "backup", {unique: false}); +} + + +// v16 migrates the backup and source fields of inbound group sessions +async function migrateBackupStatus(db: IDBDatabase, txn: IDBTransaction, localStorage: IDOMStorage, log: ILogItem): Promise { const inboundGroupSessions = txn.objectStore("inboundGroupSessions"); let countWithSession = 0; let countWithoutSession = 0; @@ -291,6 +299,7 @@ async function addInboundSessionBackupIndex(db: IDBDatabase, txn: IDBTransaction // to backup keys that were already in backup, which // the server will ignore value.source = KeySource.DeviceMessage; + cursor.update(value); countWithSession += 1; } else { countWithoutSession += 1; @@ -299,5 +308,4 @@ async function addInboundSessionBackupIndex(db: IDBDatabase, txn: IDBTransaction }); log.set("countWithoutSession", countWithoutSession); log.set("countWithSession", countWithSession); - inboundGroupSessions.createIndex("byBackup", "backup", {unique: false}); }