From 15c07ea7df187d58a4873339a13276e9ca7a0909 Mon Sep 17 00:00:00 2001 From: Beaudan Brown Date: Wed, 6 Nov 2019 16:07:15 +1100 Subject: [PATCH] Sync secondary devices again but handle the receiving of them properly --- js/background.js | 21 ++++++++++++++++----- js/models/conversations.js | 5 +---- libloki/api.js | 12 ++++-------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/js/background.js b/js/background.js index 00fda8103..ff78e5d63 100644 --- a/js/background.js +++ b/js/background.js @@ -8,6 +8,7 @@ storage, textsecure, Whisper, + libloki, BlockedNumberController */ @@ -252,7 +253,7 @@ window.lokiP2pAPI = new window.LokiP2pAPI(ourKey); window.lokiP2pAPI.on('pingContact', pubKey => { const isPing = true; - window.libloki.api.sendOnlineBroadcastMessage(pubKey, isPing); + libloki.api.sendOnlineBroadcastMessage(pubKey, isPing); }); window.lokiP2pAPI.on('online', ConversationController._handleOnline); window.lokiP2pAPI.on('offline', ConversationController._handleOffline); @@ -845,8 +846,8 @@ }); Whisper.events.on('devicePairingRequestRejected', async pubKey => { - await window.libloki.storage.removeContactPreKeyBundle(pubKey); - await window.libloki.storage.removePairingAuthorisationForSecondaryPubKey( + await libloki.storage.removeContactPreKeyBundle(pubKey); + await libloki.storage.removePairingAuthorisationForSecondaryPubKey( pubKey ); }); @@ -1164,7 +1165,7 @@ } let primaryDevice = null; - const authorisation = await window.libloki.storage.getGrantAuthorisationForSecondaryPubKey( + const authorisation = await libloki.storage.getGrantAuthorisationForSecondaryPubKey( sender ); if (authorisation) { @@ -1221,6 +1222,16 @@ if (activeAt !== null) { activeAt = activeAt || Date.now(); } + const ourAuthorisations = await libloki.storage.getPrimaryDeviceMapping( + window.storage.get('primaryDevicePubKey') + ); + const isSecondaryDevice = + ourAuthorisations && + ourAuthorisations.some(auth => auth.secondaryDevicePubKey === id); + + if (isSecondaryDevice) { + await conversation.setSecondaryStatus(true); + } if (details.profileKey) { const profileKey = window.Signal.Crypto.arrayBufferToBase64( @@ -1395,7 +1406,7 @@ const messageDescriptor = getMessageDescriptor(data); // Funnel messages to primary device conversation if multi-device - const authorisation = await window.libloki.storage.getGrantAuthorisationForSecondaryPubKey( + const authorisation = await libloki.storage.getGrantAuthorisationForSecondaryPubKey( messageDescriptor.id ); if (authorisation) { diff --git a/js/models/conversations.js b/js/models/conversations.js index bf6e4edb3..290903d22 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -192,10 +192,7 @@ }, isMe() { - return ( - this.id === this.ourNumber || - this.id === window.storage.get('primaryDevicePubKey') - ); + return this.id === window.storage.get('primaryDevicePubKey'); }, isPublic() { return this.id && this.id.match(/^publicChat:/); diff --git a/libloki/api.js b/libloki/api.js index 10940f52b..a41e3c34d 100644 --- a/libloki/api.js +++ b/libloki/api.js @@ -120,11 +120,7 @@ { ConversationCollection: Whisper.ConversationCollection } ); // Extract required contacts information out of conversations - const rawContacts = conversations.reduce((acc, conversation) => { - if (conversation.isSecondaryDevice()) { - // Don't bother syncing secondary devices - return acc; - } + const rawContacts = conversations.map(conversation => { const profile = conversation.getLokiProfile(); const number = conversation.getNumber(); const name = profile @@ -139,15 +135,15 @@ destination: number, identityKey: StringView.hexToArrayBuffer(number), }); - return acc.concat({ + return { name, verified, number, nickname: conversation.getNickname(), blocked: conversation.isBlocked(), expireTimer: conversation.get('expireTimer'), - }); - }, []); + }; + }); // Convert raw contacts to an array of buffers const contactDetails = rawContacts .filter(x => x.number !== textsecure.storage.user.getNumber())