From 030264c6895e2536d2bfd78f35a67d7b6844c084 Mon Sep 17 00:00:00 2001 From: Beaudan Brown Date: Wed, 13 Nov 2019 12:39:42 +1100 Subject: [PATCH] Fix misuse of getAllDevicePubKeysForPrimaryPubKey and rename some vars --- js/background.js | 18 +++++++++++------- libtextsecure/message_receiver.js | 11 +++-------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/js/background.js b/js/background.js index ffa504b4b..ae8aed3d7 100644 --- a/js/background.js +++ b/js/background.js @@ -1235,14 +1235,18 @@ if (activeAt !== null) { activeAt = activeAt || Date.now(); } - const ourAuthorisations = await libloki.storage.getPrimaryDeviceMapping( - window.storage.get('primaryDevicePubKey') + const ourPrimaryKey = window.storage.get('primaryDevicePubKey'); + const ourDevices = await libloki.storage.getAllDevicePubKeysForPrimaryPubKey( + ourPrimaryKey ); - const isSecondaryDevice = - ourAuthorisations && - ourAuthorisations.some(auth => auth.secondaryDevicePubKey === id); - - if (isSecondaryDevice) { + // TODO: We should probably just *not* send any secondary devices and + // just load them all and send FRs when we get the mapping + const isOurSecondaryDevice = + id !== ourPrimaryKey && + ourDevices && + ourDevices.some(devicePubKey => devicePubKey === id); + + if (isOurSecondaryDevice) { await conversation.setSecondaryStatus(true); } diff --git a/libtextsecure/message_receiver.js b/libtextsecure/message_receiver.js index 70422f6c7..759924c18 100644 --- a/libtextsecure/message_receiver.js +++ b/libtextsecure/message_receiver.js @@ -1104,13 +1104,13 @@ MessageReceiver.prototype.extend({ window.log.info( `Received pairing authorisation from ${primaryDevicePubKey}` ); - await libloki.storage.savePairingAuthorisation(pairingAuthorisation); // Set current device as secondary. // This will ensure the authorisation is sent // along with each friend request. window.storage.remove('secondaryDeviceStatus'); window.storage.put('isSecondaryDevice', true); window.storage.put('primaryDevicePubKey', primaryDevicePubKey); + await libloki.storage.savePairingAuthorisation(pairingAuthorisation); const primaryConversation = await ConversationController.getOrCreateAndWait( primaryDevicePubKey, 'private' @@ -1464,16 +1464,11 @@ MessageReceiver.prototype.extend({ async handleSyncMessage(envelope, syncMessage) { const ourNumber = textsecure.storage.user.getNumber(); // NOTE: Maybe we should be caching this list? - const ourAuthorisations = await libloki.storage.getPrimaryDeviceMapping( + const ourDevices = await libloki.storage.getAllDevicePubKeysForPrimaryPubKey( window.storage.get('primaryDevicePubKey') ); const validSyncSender = - ourAuthorisations && - ourAuthorisations.some( - auth => - auth.secondaryDevicePubKey === ourNumber || - auth.primaryDevicePubKey === ourNumber - ); + ourDevices && ourDevices.some(devicePubKey => devicePubKey === ourNumber); if (!validSyncSender) { throw new Error( "Received sync message from a device we aren't paired with"