1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-12-19 10:22:30 +03:00

Load/Store account data events

This commit is contained in:
Kegan Dougal
2017-02-02 17:41:49 +00:00
parent ad9d58ebc2
commit 9581e48bcb

View File

@@ -261,8 +261,8 @@ IndexedDBStore.prototype.startup = function() {
this.backend.loadSyncToken(), this.backend.loadSyncToken(),
]); ]);
}).then((values) => { }).then((values) => {
console.log("Loaded data from database. Reticulating splines...");
const [users, accountData, rooms, syncToken] = values; const [users, accountData, rooms, syncToken] = values;
console.log("Loaded data from database. Reticulating splines...",accountData, users);
users.forEach((u) => { users.forEach((u) => {
this._userModifiedMap[u.userId] = u.getLastModifiedTime(); this._userModifiedMap[u.userId] = u.getLastModifiedTime();
this.storeUser(u); this.storeUser(u);
@@ -305,7 +305,15 @@ IndexedDBStore.prototype._syncToDatabase = function() {
this._userModifiedMap[u.userId] = u.getLastModifiedTime(); this._userModifiedMap[u.userId] = u.getLastModifiedTime();
}); });
return this.backend.persistUsers(changedUsers); // TODO: work out changed account data events. They don't have timestamps or IDs.
// so we'll need to hook into storeAccountDataEvents instead to catch them when
// they update from /sync
const changedAccountData = Object.keys(this.accountData).map((etype) => this.accountData[etype]);
return q.all([
this.backend.persistUsers(changedUsers),
this.backend.persistAccountData(changedAccountData),
]);
}; };
function createDatabase(db) { function createDatabase(db) {
@@ -317,7 +325,7 @@ function createDatabase(db) {
// Make account data store, clobber based on event type. // Make account data store, clobber based on event type.
// (event.type property of MatrixEvent objects) // (event.type property of MatrixEvent objects)
db.createObjectStore("accountData", { keyPath: ["event.type"] }); db.createObjectStore("accountData", { keyPath: ["type"] });
// Make configuration store (sync tokens, etc), always clobber (const key). // Make configuration store (sync tokens, etc), always clobber (const key).
db.createObjectStore("config", { keyPath: ["clobber"] }); db.createObjectStore("config", { keyPath: ["clobber"] });