diff --git a/src/matrix/Session.js b/src/matrix/Session.js index 5f306438..cd09c1f4 100644 --- a/src/matrix/Session.js +++ b/src/matrix/Session.js @@ -392,12 +392,10 @@ export class Session { if (this._e2eeAccount && deviceOneTimeKeysCount) { changes.e2eeAccountChanges = this._e2eeAccount.writeSync(deviceOneTimeKeysCount, txn, log); } - - if (this._deviceTracker) { - const deviceLists = syncResponse.device_lists; - if (deviceLists) { - await log.wrap("deviceTracker", log => this._deviceTracker.writeDeviceChanges(deviceLists, txn, log)); - } + + const deviceLists = syncResponse.device_lists; + if (this._deviceTracker && Array.isArray(deviceLists.changed) && deviceLists.changed.length) { + await log.wrap("deviceLists", log => this._deviceTracker.writeDeviceChanges(deviceLists.changed, txn, log)); } const toDeviceEvents = syncResponse.to_device?.events; diff --git a/src/matrix/e2ee/DeviceTracker.js b/src/matrix/e2ee/DeviceTracker.js index 9606872e..89ceae7b 100644 --- a/src/matrix/e2ee/DeviceTracker.js +++ b/src/matrix/e2ee/DeviceTracker.js @@ -43,7 +43,7 @@ export class DeviceTracker { this._ownDeviceId = ownDeviceId; } - async writeDeviceChanges(deviceLists, txn, log) { + async writeDeviceChanges(changed, txn, log) { const {userIdentities} = txn; // TODO: should we also look at left here to handle this?: // the usual problem here is that you share a room with a user, @@ -52,16 +52,15 @@ export class DeviceTracker { // At which point you come online, all of this happens in the gap, // and you don't notice that they ever left, // and so the client doesn't invalidate their device cache for the user - if (Array.isArray(deviceLists.changed) && deviceLists.changed.length) { - await Promise.all(deviceLists.changed.map(async userId => { - const user = await userIdentities.get(userId); - if (user) { - log.log({l: "outdated", id: userId}) - user.deviceTrackingStatus = TRACKING_STATUS_OUTDATED; - userIdentities.set(user); - } - })); - } + log.set("changed", changed.length); + await Promise.all(changed.map(async userId => { + const user = await userIdentities.get(userId); + if (user) { + log.log({l: "outdated", id: userId}); + user.deviceTrackingStatus = TRACKING_STATUS_OUTDATED; + userIdentities.set(user); + } + })); } writeMemberChanges(room, memberChanges, txn) {