diff --git a/spec/integ/matrix-client-crypto.spec.js b/spec/integ/matrix-client-crypto.spec.js index 17955b466..e7d78f947 100644 --- a/spec/integ/matrix-client-crypto.spec.js +++ b/spec/integ/matrix-client-crypto.spec.js @@ -154,11 +154,15 @@ function aliDownloadsKeys() { // check that the localStorage is updated as we expect (not sure this is // an integration test, but meh) - return Promise.all([p1, p2]).then(function() { - const devices = aliTestClient.storage.getEndToEndDevicesForUser(bobUserId); - expect(devices[bobDeviceId].keys).toEqual(bobTestClient.deviceKeys.keys); - expect(devices[bobDeviceId].verified). - toBe(0); // DeviceVerification.UNVERIFIED + return Promise.all([p1, p2]).then(() => { + return aliTestClient.client._crypto._deviceList.saveIfDirty(); + }).then(() => { + aliTestClient.cryptoStore.getEndToEndDeviceData(null, (data) => { + const devices = data.devices[bobUserId]; + expect(devices[bobDeviceId].keys).toEqual(bobTestClient.deviceKeys.keys); + expect(devices[bobDeviceId].verified). + toBe(0); // DeviceVerification.UNVERIFIED + }); }); } diff --git a/src/crypto/DeviceList.js b/src/crypto/DeviceList.js index 2ed10449f..ee5716e6d 100644 --- a/src/crypto/DeviceList.js +++ b/src/crypto/DeviceList.js @@ -193,8 +193,9 @@ export default class DeviceList { } /** - * Download the keys for a list of users and stores the keys in the session - * store. + * Ensures up to date keys for a list of users are stored in the session store, + * downloading and storing them if they're not (or if forceDownload is + * true). * @param {Array} userIds The users to fetch. * @param {bool} forceDownload Always download the keys even if cached. * @@ -427,7 +428,6 @@ export default class DeviceList { for (const userId of Object.keys(this._deviceTrackingStatus)) { this._deviceTrackingStatus[userId] = TRACKING_STATUS_NOT_TRACKED; } - console.log("stopped tracking all: "+JSON.stringify(this._deviceTrackingStatus)); this._dirty = true; } @@ -513,6 +513,9 @@ export default class DeviceList { const finished = (newDevices) => { users.forEach((u) => { + this._devices[u] = newDevices[u]; + this._dirty = true; + // we may have queued up another download request for this user // since we started this request. If that happens, we should // ignore the completion of the first one. @@ -528,8 +531,6 @@ export default class DeviceList { // we didn't get any new invalidations since this download started: // this user's device list is now up to date. this._deviceTrackingStatus[u] = TRACKING_STATUS_UP_TO_DATE; - this._devices[u] = newDevices[u]; - this._dirty = true; console.log("Device list for", u, "now up to date"); } else { this._deviceTrackingStatus[u] = TRACKING_STATUS_PENDING_DOWNLOAD;