From 1451fcb040d26c5f6ae51a13d7382c34db45ab8e Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 29 Apr 2020 17:01:50 +0100 Subject: [PATCH] Add initialFetch param to willUpdateDevices / devicesUpdated This indicates whether the device database is being populated initially --- src/client.js | 4 ++++ src/crypto/DeviceList.js | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/client.js b/src/client.js index cad322be1..6ae309616 100644 --- a/src/client.js +++ b/src/client.js @@ -5593,12 +5593,16 @@ MatrixClient.prototype.generateClientSecret = function() { * Fires whenever the stored devices for a user have changed * @event module:client~MatrixClient#"crypto.devicesUpdated" * @param {String[]} users A list of user IDs that were updated + * @param {bool} initialFetch If true, the store was empty (apart + * from our own device) and has been seeded. */ /** * Fires whenever the stored devices for a user will be updated * @event module:client~MatrixClient#"crypto.willUpdateDevices" * @param {String[]} users A list of user IDs that will be updated + * @param {bool} initialFetch If true, the store is empty (apart + * from our own device) and is being seeded. */ /** diff --git a/src/crypto/DeviceList.js b/src/crypto/DeviceList.js index aeb3a4487..5925f8adb 100644 --- a/src/crypto/DeviceList.js +++ b/src/crypto/DeviceList.js @@ -109,6 +109,9 @@ export class DeviceList extends EventEmitter { this._savePromiseTime = null; // The timer used to delay the save this._saveTimer = null; + // True if we have fetched data from the server or loaded a non-empty + // set of device data from the store + this._hasFetched = null; } /** @@ -118,6 +121,7 @@ export class DeviceList extends EventEmitter { await this._cryptoStore.doTxn( 'readonly', [IndexedDBCryptoStore.STORE_DEVICE_DATA], (txn) => { this._cryptoStore.getEndToEndDeviceData(txn, (deviceData) => { + this._hasFetched = Boolean(deviceData && deviceData.devices); this._devices = deviceData ? deviceData.devices : {}, this._crossSigningInfo = deviceData ? deviceData.crossSigningInfo || {} : {}; @@ -652,7 +656,7 @@ export class DeviceList extends EventEmitter { }); const finished = (success) => { - this.emit("crypto.willUpdateDevices", users); + this.emit("crypto.willUpdateDevices", users, !this._hasFetched); users.forEach((u) => { this._dirty = true; @@ -678,7 +682,8 @@ export class DeviceList extends EventEmitter { } }); this.saveIfDirty(); - this.emit("crypto.devicesUpdated", users); + this.emit("crypto.devicesUpdated", users, !this._hasFetched); + this._hasFetched = true; }; return prom;