Unique constraint and prevent some undefined bugs
This commit is contained in:
parent
d97eced37b
commit
de0a5c7b78
|
@ -940,7 +940,8 @@ async function updateToLokiSchemaVersion2(currentVersion, instance) {
|
|||
primaryDevicePubKey VARCHAR(255),
|
||||
secondaryDevicePubKey VARCHAR(255),
|
||||
isGranted BOOLEAN,
|
||||
json TEXT
|
||||
json TEXT,
|
||||
UNIQUE(primaryDevicePubKey, secondaryDevicePubKey)
|
||||
);`
|
||||
);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* global window, textsecure, log, Whisper, dcodeIO, StringView */
|
||||
/* global window, textsecure, log, Whisper, dcodeIO, StringView, ConversationController */
|
||||
|
||||
// eslint-disable-next-line func-names
|
||||
(function() {
|
||||
|
@ -31,7 +31,7 @@
|
|||
let p2pPort = null;
|
||||
let type;
|
||||
|
||||
if (!window.localLokiServer.isListening()) {
|
||||
if (!window.localLokiServer || !window.localLokiServer.isListening()) {
|
||||
type = textsecure.protobuf.LokiAddressMessage.Type.HOST_UNREACHABLE;
|
||||
} else {
|
||||
// clearnet change: getMyLokiAddress -> getMyClearIP
|
||||
|
@ -166,7 +166,7 @@
|
|||
);
|
||||
// Send profile name to secondary device
|
||||
const ourNumber = textsecure.storage.user.getNumber();
|
||||
const conversation = await window.ConversationController.getOrCreateAndWait(
|
||||
const conversation = await ConversationController.getOrCreateAndWait(
|
||||
ourNumber,
|
||||
'private'
|
||||
);
|
||||
|
|
|
@ -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) {
|
||||
if (typeof lokiFileServerAPI === 'undefined') {
|
||||
// If this is not defined then we are initiating a pairing
|
||||
return [];
|
||||
}
|
||||
const deviceMapping = await lokiFileServerAPI.getUserDeviceMapping(pubKey);
|
||||
if (!deviceMapping) {
|
||||
return [];
|
||||
}
|
||||
let { authorisations } = deviceMapping;
|
||||
if (!authorisations) {
|
||||
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
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue