store account data in storage

needs a resync, need to think how to handle this
This commit is contained in:
Bruno Windels 2020-09-17 10:39:51 +02:00
parent 00eade1c16
commit abfde76e24
5 changed files with 26 additions and 3 deletions

View File

@ -289,6 +289,16 @@ export class Session {
if (Array.isArray(toDeviceEvents)) { if (Array.isArray(toDeviceEvents)) {
this._deviceMessageHandler.writeSync(toDeviceEvents, txn); 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; return changes;
} }

View File

@ -228,7 +228,8 @@ export class Sync {
// to discard outbound session when somebody leaves a room // to discard outbound session when somebody leaves a room
// and to create room key messages when somebody leaves // and to create room key messages when somebody leaves
storeNames.outboundGroupSessions, storeNames.outboundGroupSessions,
storeNames.operations storeNames.operations,
storeNames.accountData,
]); ]);
} }

View File

@ -28,7 +28,8 @@ export const STORE_NAMES = Object.freeze([
"inboundGroupSessions", "inboundGroupSessions",
"outboundGroupSessions", "outboundGroupSessions",
"groupSessionDecryptions", "groupSessionDecryptions",
"operations" "operations",
"accountData",
]); ]);
export const STORE_MAP = Object.freeze(STORE_NAMES.reduce((nameMap, name) => { export const STORE_MAP = Object.freeze(STORE_NAMES.reduce((nameMap, name) => {

View File

@ -31,6 +31,7 @@ import {InboundGroupSessionStore} from "./stores/InboundGroupSessionStore.js";
import {OutboundGroupSessionStore} from "./stores/OutboundGroupSessionStore.js"; import {OutboundGroupSessionStore} from "./stores/OutboundGroupSessionStore.js";
import {GroupSessionDecryptionStore} from "./stores/GroupSessionDecryptionStore.js"; import {GroupSessionDecryptionStore} from "./stores/GroupSessionDecryptionStore.js";
import {OperationStore} from "./stores/OperationStore.js"; import {OperationStore} from "./stores/OperationStore.js";
import {AccountDataStore} from "./stores/AccountDataStore.js";
export class Transaction { export class Transaction {
constructor(txn, allowedStoreNames) { constructor(txn, allowedStoreNames) {
@ -111,6 +112,10 @@ export class Transaction {
return this._store("operations", idbStore => new OperationStore(idbStore)); return this._store("operations", idbStore => new OperationStore(idbStore));
} }
get accountData() {
return this._store("accountData", idbStore => new AccountDataStore(idbStore));
}
complete() { complete() {
return txnAsPromise(this._txn); return txnAsPromise(this._txn);
} }

View File

@ -10,7 +10,8 @@ export const schema = [
createMemberStore, createMemberStore,
migrateSession, migrateSession,
createE2EEStores, createE2EEStores,
migrateEncryptionFlag migrateEncryptionFlag,
createAccountDataStore
]; ];
// TODO: how to deal with git merge conflicts of this array? // 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"});
}