From abfde76e24aaca640b002023a6580a653afa6127 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 17 Sep 2020 10:39:51 +0200 Subject: [PATCH] store account data in storage needs a resync, need to think how to handle this --- src/matrix/Session.js | 10 ++++++++++ src/matrix/Sync.js | 3 ++- src/matrix/storage/common.js | 3 ++- src/matrix/storage/idb/Transaction.js | 5 +++++ src/matrix/storage/idb/schema.js | 8 +++++++- 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/matrix/Session.js b/src/matrix/Session.js index 75840790..197c0f3f 100644 --- a/src/matrix/Session.js +++ b/src/matrix/Session.js @@ -289,6 +289,16 @@ export class Session { if (Array.isArray(toDeviceEvents)) { this._deviceMessageHandler.writeSync(toDeviceEvents, txn); } + + // store account data + const accountData = syncResponse["account_data"]; + if (Array.isArray(accountData?.events)) { + for (const event of accountData.events) { + if (typeof event.type === "string") { + txn.accountData.set(event); + } + } + } return changes; } diff --git a/src/matrix/Sync.js b/src/matrix/Sync.js index ca76e57a..63be2ce2 100644 --- a/src/matrix/Sync.js +++ b/src/matrix/Sync.js @@ -228,7 +228,8 @@ export class Sync { // to discard outbound session when somebody leaves a room // and to create room key messages when somebody leaves storeNames.outboundGroupSessions, - storeNames.operations + storeNames.operations, + storeNames.accountData, ]); } diff --git a/src/matrix/storage/common.js b/src/matrix/storage/common.js index f74dafdc..88238a11 100644 --- a/src/matrix/storage/common.js +++ b/src/matrix/storage/common.js @@ -28,7 +28,8 @@ export const STORE_NAMES = Object.freeze([ "inboundGroupSessions", "outboundGroupSessions", "groupSessionDecryptions", - "operations" + "operations", + "accountData", ]); export const STORE_MAP = Object.freeze(STORE_NAMES.reduce((nameMap, name) => { diff --git a/src/matrix/storage/idb/Transaction.js b/src/matrix/storage/idb/Transaction.js index d28d802f..08eacb34 100644 --- a/src/matrix/storage/idb/Transaction.js +++ b/src/matrix/storage/idb/Transaction.js @@ -31,6 +31,7 @@ import {InboundGroupSessionStore} from "./stores/InboundGroupSessionStore.js"; import {OutboundGroupSessionStore} from "./stores/OutboundGroupSessionStore.js"; import {GroupSessionDecryptionStore} from "./stores/GroupSessionDecryptionStore.js"; import {OperationStore} from "./stores/OperationStore.js"; +import {AccountDataStore} from "./stores/AccountDataStore.js"; export class Transaction { constructor(txn, allowedStoreNames) { @@ -111,6 +112,10 @@ export class Transaction { return this._store("operations", idbStore => new OperationStore(idbStore)); } + get accountData() { + return this._store("accountData", idbStore => new AccountDataStore(idbStore)); + } + complete() { return txnAsPromise(this._txn); } diff --git a/src/matrix/storage/idb/schema.js b/src/matrix/storage/idb/schema.js index b78c117b..4d0d45ac 100644 --- a/src/matrix/storage/idb/schema.js +++ b/src/matrix/storage/idb/schema.js @@ -10,7 +10,8 @@ export const schema = [ createMemberStore, migrateSession, createE2EEStores, - migrateEncryptionFlag + migrateEncryptionFlag, + createAccountDataStore ]; // TODO: how to deal with git merge conflicts of this array? @@ -97,3 +98,8 @@ async function migrateEncryptionFlag(db, txn) { } } } + +// v6 +function createAccountDataStore(db) { + db.createObjectStore("accountData", {keyPath: "type"}); +}