From 14ad32bcd22f0a06e75610b1551d5b1544b79d1d Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 19 Jul 2017 13:19:26 +0100 Subject: [PATCH] Make Crypto.importRoomKeys async --- src/client.js | 7 +++++-- src/crypto/index.js | 19 +++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/client.js b/src/client.js index cd2ce969d..1a5ba159e 100644 --- a/src/client.js +++ b/src/client.js @@ -632,12 +632,15 @@ MatrixClient.prototype.exportRoomKeys = function() { * Import a list of room keys previously exported by exportRoomKeys * * @param {Object[]} keys a list of session export objects + * + * @return {module:client.Promise} a promise which resolves when the keys + * have been imported */ -MatrixClient.prototype.importRoomKeys = async function(keys) { +MatrixClient.prototype.importRoomKeys = function(keys) { if (!this._crypto) { throw new Error("End-to-end encryption disabled"); } - this._crypto.importRoomKeys(keys); + return this._crypto.importRoomKeys(keys); }; // Room ops diff --git a/src/crypto/index.js b/src/crypto/index.js index 73eaa40be..6f3970fe1 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -703,17 +703,20 @@ Crypto.prototype.exportRoomKeys = function() { * Import a list of room keys previously exported by exportRoomKeys * * @param {Object[]} keys a list of session export objects + * @return {module:client.Promise} a promise which resolves once the keys have been imported */ Crypto.prototype.importRoomKeys = function(keys) { - keys.map((session) => { - if (!session.room_id || !session.algorithm) { - console.warn("ignoring session entry with missing fields", session); - return; - } + return Promise.map( + keys, (key) => { + if (!key.room_id || !key.algorithm) { + console.warn("ignoring room key entry with missing fields", key); + return; + } - const alg = this._getRoomDecryptor(session.room_id, session.algorithm); - alg.importRoomKey(session); - }); + const alg = this._getRoomDecryptor(key.room_id, key.algorithm); + alg.importRoomKey(key); + }, + ); }; /**