diff --git a/keyserver/src/utils/olm-utils.js b/keyserver/src/utils/olm-utils.js --- a/keyserver/src/utils/olm-utils.js +++ b/keyserver/src/utils/olm-utils.js @@ -6,6 +6,7 @@ Utility as OlmUtility, Session as OlmSession, } from '@commapp/olm'; +import invariant from 'invariant'; import { getRustAPI } from 'rust-node-addon'; import uuid from 'uuid'; @@ -111,32 +112,42 @@ throw new ServerError('missing_identity_info'); } - await fetchCallUpdateOlmAccount('content', (contentAccount: OlmAccount) => { - contentAccount.generate_one_time_keys(numberOfKeys); - const contentOneTimeKeys = getOneTimeKeyValuesFromBlob( - contentAccount.one_time_keys(), - ); + let contentOneTimeKeys: ?$ReadOnlyArray; + let notifOneTimeKeys: ?$ReadOnlyArray; + + await Promise.all([ + fetchCallUpdateOlmAccount('content', (contentAccount: OlmAccount) => { + contentAccount.generate_one_time_keys(numberOfKeys); + contentOneTimeKeys = getOneTimeKeyValuesFromBlob( + contentAccount.one_time_keys(), + ); + contentAccount.mark_keys_as_published(); + }), + fetchCallUpdateOlmAccount('notifications', (notifAccount: OlmAccount) => { + notifAccount.generate_one_time_keys(numberOfKeys); + notifOneTimeKeys = getOneTimeKeyValuesFromBlob( + notifAccount.one_time_keys(), + ); + notifAccount.mark_keys_as_published(); + }), + ]); - return fetchCallUpdateOlmAccount( - 'notifications', - async (notifAccount: OlmAccount) => { - notifAccount.generate_one_time_keys(numberOfKeys); - const notifOneTimeKeys = getOneTimeKeyValuesFromBlob( - notifAccount.one_time_keys(), - ); - await rustAPI.uploadOneTimeKeys( - identityInfo.userId, - deviceID, - identityInfo.accessToken, - contentOneTimeKeys, - notifOneTimeKeys, - ); - - notifAccount.mark_keys_as_published(); - contentAccount.mark_keys_as_published(); - }, - ); - }); + invariant( + contentOneTimeKeys, + 'content one-time keys not set after fetchCallUpdateOlmAccount', + ); + invariant( + notifOneTimeKeys, + 'notif one-time keys not set after fetchCallUpdateOlmAccount', + ); + + await rustAPI.uploadOneTimeKeys( + identityInfo.userId, + deviceID, + identityInfo.accessToken, + contentOneTimeKeys, + notifOneTimeKeys, + ); } async function getContentSigningKey(): Promise {