|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
/* global window, libsignal, textsecure, Signal, lokiFileServerAPI */
|
|
|
|
|
/* global window, libsignal, textsecure, Signal,
|
|
|
|
|
lokiFileServerAPI, ConversationController */
|
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line func-names
|
|
|
|
|
(function() {
|
|
|
|
@ -115,29 +116,36 @@
|
|
|
|
|
|
|
|
|
|
// fetches device mappings from server.
|
|
|
|
|
async function getPrimaryDeviceMapping(pubKey) {
|
|
|
|
|
const deviceMapping = await lokiFileServerAPI.getUserDeviceMapping(pubKey);
|
|
|
|
|
if (!deviceMapping) {
|
|
|
|
|
if (typeof lokiFileServerAPI === 'undefined') {
|
|
|
|
|
// If this is not defined then we are initiating a pairing
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
let { authorisations } = deviceMapping;
|
|
|
|
|
if (!authorisations) {
|
|
|
|
|
const deviceMapping = await lokiFileServerAPI.getUserDeviceMapping(pubKey);
|
|
|
|
|
if (!deviceMapping) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
if (deviceMapping.isPrimary !== '1') {
|
|
|
|
|
const { primaryDevicePubKey } = authorisations.find(
|
|
|
|
|
authorisation => authorisation.secondaryDevicePubKey === pubKey
|
|
|
|
|
);
|
|
|
|
|
let authorisations = deviceMapping.authorisations || [];
|
|
|
|
|
if (deviceMapping.isPrimary === '0') {
|
|
|
|
|
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(
|
|
|
|
|
const primaryDeviceMapping = await lokiFileServerAPI.getUserDeviceMapping(
|
|
|
|
|
primaryDevicePubKey
|
|
|
|
|
));
|
|
|
|
|
);
|
|
|
|
|
if (!primaryDeviceMapping) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
({ authorisations } = primaryDeviceMapping);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return authorisations || [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if the device is a secondary device,
|
|
|
|
|
// fetch the device mappings for its primary device
|
|
|
|
|
async function saveAllPairingAuthorisationsFor(pubKey) {
|
|
|
|
@ -161,6 +169,10 @@
|
|
|
|
|
|
|
|
|
|
// Transforms signatures from base64 to ArrayBuffer!
|
|
|
|
|
async function getGrantAuthorisationForSecondaryPubKey(secondaryPubKey) {
|
|
|
|
|
const conversation = ConversationController.get(secondaryPubKey);
|
|
|
|
|
if (!conversation || conversation.isPublic() || conversation.isRss()) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
const authorisation = await window.Signal.Data.getGrantAuthorisationForSecondaryPubKey(
|
|
|
|
|
secondaryPubKey
|
|
|
|
|
);
|
|
|
|
|