1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-26 17:03:12 +03:00

Rewrite olmlib.ensureOlmSessionsForDevices as async

This is non-functional. It just looks a lot prettier.
This commit is contained in:
Richard van der Hoff
2017-07-26 08:04:46 +01:00
parent a2d7b221ee
commit ef889963d9

View File

@@ -121,7 +121,7 @@ module.exports.encryptMessageForDevice = async function(
* an Object mapping from userId to deviceId to
* {@link module:crypto~OlmSessionResult}
*/
module.exports.ensureOlmSessionsForDevices = function(
module.exports.ensureOlmSessionsForDevices = async function(
olmDevice, baseApis, devicesByUser,
) {
const devicesWithoutSession = [
@@ -151,7 +151,7 @@ module.exports.ensureOlmSessionsForDevices = function(
}
if (devicesWithoutSession.length === 0) {
return Promise.resolve(result);
return result;
}
// TODO: this has a race condition - if we try to send another message
@@ -161,9 +161,10 @@ module.exports.ensureOlmSessionsForDevices = function(
// That should eventually resolve itself, but it's poor form.
const oneTimeKeyAlgorithm = "signed_curve25519";
return baseApis.claimOneTimeKeys(
const res = await baseApis.claimOneTimeKeys(
devicesWithoutSession, oneTimeKeyAlgorithm,
).then(function(res) {
);
const otk_res = res.one_time_keys || {};
const promises = [];
for (const userId in devicesByUser) {
@@ -205,8 +206,9 @@ module.exports.ensureOlmSessionsForDevices = function(
);
}
}
return Promise.all(promises).return(result);
});
await Promise.all(promises);
return result;
};
async function _verifyKeyAndStartSession(olmDevice, oneTimeKey, userId, deviceInfo) {