Skip to content

Commit

Permalink
Include DeviceInfo in deviceVerificationChanged events
Browse files Browse the repository at this point in the history
... to help the UI update itself
  • Loading branch information
richvdh committed Feb 3, 2017
1 parent bd4de48 commit a3cc8eb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,10 @@ function _setDeviceVerification(client, userId, deviceId, verified, blocked, kno
if (!client._crypto) {
throw new Error("End-to-End encryption disabled");
}
client._crypto.setDeviceVerification(userId, deviceId, verified, blocked, known);
client.emit("deviceVerificationChanged", userId, deviceId);
const dev = client._crypto.setDeviceVerification(
userId, deviceId, verified, blocked, known,
);
client.emit("deviceVerificationChanged", userId, deviceId, dev);
}

/**
Expand Down Expand Up @@ -3163,6 +3165,7 @@ module.exports.CRYPTO_ENABLED = CRYPTO_ENABLED;
* @event module:client~MatrixClient#"deviceVerificationChanged"
* @param {string} userId the owner of the verified device
* @param {string} deviceId the id of the verified device
* @param {module:crypto/deviceinfo} deviceInfo updated device information
*/

/**
Expand Down
12 changes: 7 additions & 5 deletions src/crypto/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ Crypto.prototype.listDeviceKeys = function(userId) {
*
* @param {?boolean} known whether to mark that the user has been made aware of
* the existence of this device. Null to leave unchanged
*
* @return {module:crypto/deviceinfo} updated DeviceInfo
*/
Crypto.prototype.setDeviceVerification = function(userId, deviceId, verified,
blocked, known) {
Expand Down Expand Up @@ -414,12 +416,12 @@ Crypto.prototype.setDeviceVerification = function(userId, deviceId, verified,
knownStatus = known;
}

if (dev.verified === verificationStatus && dev.known === knownStatus) {
return;
if (dev.verified !== verificationStatus || dev.known !== knownStatus) {
dev.verified = verificationStatus;
dev.known = knownStatus;
this._sessionStore.storeEndToEndDevicesForUser(userId, devices);
}
dev.verified = verificationStatus;
dev.known = knownStatus;
this._sessionStore.storeEndToEndDevicesForUser(userId, devices);
return DeviceInfo.fromStorage(dev, deviceId);
};


Expand Down

0 comments on commit a3cc8eb

Please sign in to comment.