pull/548/head
sachaaaaa 6 years ago
parent 1f3311bc5d
commit 53bdf14321

@ -12,7 +12,6 @@
Whisper, Whisper,
clipboard, clipboard,
libloki, libloki,
lokiFileServerAPI,
*/ */
/* eslint-disable more/no-then */ /* eslint-disable more/no-then */

@ -114,31 +114,40 @@
} }
// fetches device mappings from server. // fetches device mappings from server.
// if the device is a secondary device, async function getPrimaryDeviceMapping(pubKey) {
// fetch the device mappings for its primary device
async function saveAllPairingAuthorisationsFor(pubKey) {
const deviceMapping = await lokiFileServerAPI.getUserDeviceMapping(pubKey); const deviceMapping = await lokiFileServerAPI.getUserDeviceMapping(pubKey);
let { authorisations } = deviceMapping || {}; if (!deviceMapping) {
if (deviceMapping) { return [];
}
let { authorisations } = deviceMapping;
if (!authorisations) {
return [];
}
if (deviceMapping.isPrimary !== '1') { if (deviceMapping.isPrimary !== '1') {
const { primaryDevicePubKey } = const { primaryDevicePubKey } = authorisations.find(
authorisations.find(
authorisation => authorisation.secondaryDevicePubKey === pubKey authorisation => authorisation.secondaryDevicePubKey === pubKey
) || {}; );
if (primaryDevicePubKey) { if (primaryDevicePubKey) {
({ authorisations } = // do NOT call getprimaryDeviceMapping recursively
(await lokiFileServerAPI.getUserDeviceMapping( // in case both devices are out of sync and think they are
// each others' secondary pubkey.
({ authorisations } = await lokiFileServerAPI.getUserDeviceMapping(
primaryDevicePubKey primaryDevicePubKey
)) || {}); ));
}
} }
return authorisations || [];
}
// if the device is a secondary device,
// fetch the device mappings for its primary device
async function saveAllPairingAuthorisationsFor(pubKey) {
const authorisations = await getPrimaryDeviceMapping(pubKey);
await Promise.all( await Promise.all(
authorisations.map(authorisation => authorisations.map(authorisation =>
savePairingAuthorisation(authorisation) savePairingAuthorisation(authorisation)
) )
); );
} }
}
}
function savePairingAuthorisation(authorisation) { function savePairingAuthorisation(authorisation) {
return window.Signal.Data.createOrUpdatePairingAuthorisation(authorisation); return window.Signal.Data.createOrUpdatePairingAuthorisation(authorisation);

Loading…
Cancel
Save