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