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