From 5e0f09075d601f772baf05422b543fa0f5cf5b12 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Sun, 4 Sep 2016 23:31:38 +0100 Subject: [PATCH] MatrixClient.getStoredDevicesForUser Implement MatrixClient.getStoredDevicesForUser which uses Crypto.getStoredDevicesForUser, which is more powerful than listDeviceKeys, and isn't deprecated. Also a couple of accessors for DeviceInfo. --- lib/client.js | 18 ++++++++++++++++++ lib/crypto-deviceinfo.js | 18 ++++++++++++++++++ lib/crypto.js | 4 ++-- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/client.js b/lib/client.js index a9c2ac740..086f3d77d 100644 --- a/lib/client.js +++ b/lib/client.js @@ -308,6 +308,8 @@ MatrixClient.prototype.downloadKeys = function(userIds, forceDownload) { /** * List the stored device keys for a user id * + * @deprecated prefer {@link module:client#getStoredDevicesForUser} + * * @param {string} userId the user to list keys for. * * @return {object[]} list of devices with "id", "verified", "blocked", @@ -320,6 +322,22 @@ MatrixClient.prototype.listDeviceKeys = function(userId) { return this._crypto.listDeviceKeys(userId); }; +/** + * Get the stored device keys for a user id + * + * @param {string} userId the user to list keys for. + * + * @return {module:crypto-deviceinfo[]} list of devices + */ +MatrixClient.prototype.getStoredDevicesForUser = function(userId) { + if (this._crypto === null) { + throw new Error("End-to-end encryption disabled"); + } + return this._crypto.getStoredDevicesForUser(userId); +}; + + + /** * Mark the given device as verified * diff --git a/lib/crypto-deviceinfo.js b/lib/crypto-deviceinfo.js index ac18996c9..a7348cd55 100644 --- a/lib/crypto-deviceinfo.js +++ b/lib/crypto-deviceinfo.js @@ -112,6 +112,24 @@ DeviceInfo.prototype.getDisplayname = function() { return this.unsigned.device_display_name || null; }; +/** + * Returns true if this device is blocked + * + * @return {Boolean} true if blocked + */ +DeviceInfo.prototype.isBlocked = function() { + return this.verified == DeviceVerification.BLOCKED; +}; + +/** + * Returns true if this device is verified + * + * @return {Boolean} true if verified + */ +DeviceInfo.prototype.isVerified = function() { + return this.verified == DeviceVerification.VERIFIED; +}; + /** * @enum */ diff --git a/lib/crypto.js b/lib/crypto.js index 213b0ec9c..dda0c8c35 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -385,8 +385,8 @@ Crypto.prototype.listDeviceKeys = function(userId) { result.push({ id: device.deviceId, key: ed25519Key, - verified: Boolean(device.verified == DeviceVerification.VERIFIED), - blocked: Boolean(device.verified == DeviceVerification.BLOCKED), + verified: Boolean(device.isVerified()), + blocked: Boolean(device.isBlocked()), display_name: device.getDisplayname(), }); }