Merge pull request #578 from BeaudanBrown/multidevice-bugs

Unique constraint and prevent some undefined bugs
pull/589/head
Beaudan Campbell-Brown 6 years ago committed by GitHub
commit 8adf6a474e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -940,7 +940,8 @@ async function updateToLokiSchemaVersion2(currentVersion, instance) {
primaryDevicePubKey VARCHAR(255), primaryDevicePubKey VARCHAR(255),
secondaryDevicePubKey VARCHAR(255), secondaryDevicePubKey VARCHAR(255),
isGranted BOOLEAN, 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 // eslint-disable-next-line func-names
(function() { (function() {
@ -31,7 +31,7 @@
let p2pPort = null; let p2pPort = null;
let type; let type;
if (!window.localLokiServer.isListening()) { if (!window.localLokiServer || !window.localLokiServer.isListening()) {
type = textsecure.protobuf.LokiAddressMessage.Type.HOST_UNREACHABLE; type = textsecure.protobuf.LokiAddressMessage.Type.HOST_UNREACHABLE;
} else { } else {
// clearnet change: getMyLokiAddress -> getMyClearIP // clearnet change: getMyLokiAddress -> getMyClearIP
@ -166,7 +166,7 @@
); );
// Send profile name to secondary device // Send profile name to secondary device
const ourNumber = textsecure.storage.user.getNumber(); const ourNumber = textsecure.storage.user.getNumber();
const conversation = await window.ConversationController.getOrCreateAndWait( const conversation = await ConversationController.getOrCreateAndWait(
ourNumber, ourNumber,
'private' 'private'
); );

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

Loading…
Cancel
Save