1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-29 16:43:09 +03:00

Make Crypto.importRoomKeys async

This commit is contained in:
Richard van der Hoff
2017-07-19 13:19:26 +01:00
parent 9ab9b9d75a
commit 14ad32bcd2
2 changed files with 16 additions and 10 deletions

View File

@@ -632,12 +632,15 @@ MatrixClient.prototype.exportRoomKeys = function() {
* Import a list of room keys previously exported by exportRoomKeys * Import a list of room keys previously exported by exportRoomKeys
* *
* @param {Object[]} keys a list of session export objects * @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) { if (!this._crypto) {
throw new Error("End-to-end encryption disabled"); throw new Error("End-to-end encryption disabled");
} }
this._crypto.importRoomKeys(keys); return this._crypto.importRoomKeys(keys);
}; };
// Room ops // Room ops

View File

@@ -703,17 +703,20 @@ Crypto.prototype.exportRoomKeys = function() {
* Import a list of room keys previously exported by exportRoomKeys * Import a list of room keys previously exported by exportRoomKeys
* *
* @param {Object[]} keys a list of session export objects * @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) { Crypto.prototype.importRoomKeys = function(keys) {
keys.map((session) => { return Promise.map(
if (!session.room_id || !session.algorithm) { keys, (key) => {
console.warn("ignoring session entry with missing fields", session); if (!key.room_id || !key.algorithm) {
return; console.warn("ignoring room key entry with missing fields", key);
} return;
}
const alg = this._getRoomDecryptor(session.room_id, session.algorithm); const alg = this._getRoomDecryptor(key.room_id, key.algorithm);
alg.importRoomKey(session); alg.importRoomKey(key);
}); },
);
}; };
/** /**