You've already forked matrix-js-sdk
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:
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user