1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-09 10:22:46 +03:00

Make it all work!

This commit is contained in:
Kegan Dougal
2017-02-10 14:27:56 +00:00
parent cc1daa5a54
commit 0d4833d6e3
2 changed files with 20 additions and 15 deletions

View File

@@ -61,8 +61,15 @@ IndexedDBStoreBackend.prototype = {
} }
// Expand as needed. // Expand as needed.
}; };
return promiseifyRequest(req).then((ev) => { return promiseifyRequest(req).then((ev) => {
this.db = ev.target.result; this.db = ev.target.result;
// add a poorly-named listener for when deleteDatabase is called
// so we can close our db connections.
this.db.onversionchange = () => {
this.db.close();
};
}); });
}, },
@@ -87,6 +94,7 @@ IndexedDBStoreBackend.prototype = {
nextBatch: nextBatch, nextBatch: nextBatch,
roomsData: roomsData, roomsData: roomsData,
}; };
console.log("persisting sync data");
return this._upsert("sync", [obj]); return this._upsert("sync", [obj]);
}, },
@@ -114,7 +122,6 @@ IndexedDBStoreBackend.prototype = {
* @return {Promise} Resolves if the users were persisted. * @return {Promise} Resolves if the users were persisted.
*/ */
persistUsers: function(users) { persistUsers: function(users) {
console.log("persistUsers =>", users);
return this._upsert("users", users); return this._upsert("users", users);
}, },
@@ -148,13 +155,14 @@ IndexedDBStoreBackend.prototype = {
return q.try(() => { return q.try(() => {
const txn = this.db.transaction(["sync"], "readonly"); const txn = this.db.transaction(["sync"], "readonly");
const store = txn.objectStore("sync"); const store = txn.objectStore("sync");
const results = selectQuery(store, undefined, (cursor) => { return selectQuery(store, undefined, (cursor) => {
return cursor.value; return cursor.value;
}).then((results) => {
if (results.length > 1) {
console.warn("loadSyncData: More than 1 sync row found.");
}
return (results.length > 0 ? results[0] : {});
}); });
if (results.length > 1) {
console.warn("loadSyncData: More than 1 sync row found.");
}
return (results.length > 0 ? results[0] : {});
}); });
}, },
@@ -251,26 +259,22 @@ IndexedDBStore.prototype.startup = function() {
return q.all([ return q.all([
this.backend.loadUsers(), this.backend.loadUsers(),
this.backend.loadAccountData(), this.backend.loadAccountData(),
this.backend.loadRooms(),
this.backend.loadSyncData(), this.backend.loadSyncData(),
]); ]);
}).then((values) => { }).then((values) => {
const [users, accountData, rooms, syncData] = values; const [users, accountData, syncData] = values;
console.log( console.log(
"Loaded data from database. Reticulating splines...", "Loaded data from database: sync from ", syncData,
accountData, users, " -- Reticulating splines...",
); );
users.forEach((u) => { users.forEach((u) => {
this._userModifiedMap[u.userId] = u.getLastModifiedTime(); this._userModifiedMap[u.userId] = u.getLastModifiedTime();
this.storeUser(u); this.storeUser(u);
}); });
this.storeAccountDataEvents(accountData); this.storeAccountDataEvents(accountData);
rooms.forEach((r) => {
this.storeRoom(r);
});
this._syncTs = Date.now(); // pretend we've written so we don't rewrite this._syncTs = Date.now(); // pretend we've written so we don't rewrite
this.setSyncToken(syncData.syncToken); this.setSyncToken(syncData.nextBatch);
this._setSyncData(syncData.syncToken, syncData.roomsData); this._setSyncData(syncData.nextBatch, syncData.roomsData);
}); });
}; };

View File

@@ -75,6 +75,7 @@ class SyncAccumulator {
if (!syncResponse.rooms) { if (!syncResponse.rooms) {
return; return;
} }
console.log("Accumulating ", syncResponse.next_batch, syncResponse);
this.nextBatch = syncResponse.next_batch; this.nextBatch = syncResponse.next_batch;
if (syncResponse.rooms.invite) { if (syncResponse.rooms.invite) {
Object.keys(syncResponse.rooms.invite).forEach((roomId) => { Object.keys(syncResponse.rooms.invite).forEach((roomId) => {