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,30 +114,39 @@
} }
// 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 [];
if (deviceMapping.isPrimary !== '1') { }
const { primaryDevicePubKey } = let { authorisations } = deviceMapping;
authorisations.find( if (!authorisations) {
authorisation => authorisation.secondaryDevicePubKey === pubKey return [];
) || {}; }
if (primaryDevicePubKey) { if (deviceMapping.isPrimary !== '1') {
({ authorisations } = const { primaryDevicePubKey } = authorisations.find(
(await lokiFileServerAPI.getUserDeviceMapping( authorisation => authorisation.secondaryDevicePubKey === pubKey
primaryDevicePubKey );
)) || {}); if (primaryDevicePubKey) {
} // do NOT call getprimaryDeviceMapping recursively
await Promise.all( // in case both devices are out of sync and think they are
authorisations.map(authorisation => // each others' secondary pubkey.
savePairingAuthorisation(authorisation) ({ authorisations } = await lokiFileServerAPI.getUserDeviceMapping(
) 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(
authorisations.map(authorisation =>
savePairingAuthorisation(authorisation)
)
);
} }
function savePairingAuthorisation(authorisation) { function savePairingAuthorisation(authorisation) {

Loading…
Cancel
Save