From 807f4cbd2aa96d812cbf5c91b2420af5ca0c8237 Mon Sep 17 00:00:00 2001 From: Beaudan Brown Date: Wed, 13 Nov 2019 17:01:21 +1100 Subject: [PATCH] Storing primary device pubkey on the conversation model for easier access, ensuring that we accept all the friend requests from the primary conversation rather than the secondary --- js/background.js | 2 +- js/models/conversations.js | 24 ++++++++++++++++++++---- libloki/storage.js | 5 ++++- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/js/background.js b/js/background.js index ae8aed3d7..227a5b93c 100644 --- a/js/background.js +++ b/js/background.js @@ -1247,7 +1247,7 @@ ourDevices.some(devicePubKey => devicePubKey === id); if (isOurSecondaryDevice) { - await conversation.setSecondaryStatus(true); + await conversation.setSecondaryStatus(true, ourPrimaryKey); } if (conversation.isFriendRequestStatusNone()) { diff --git a/js/models/conversations.js b/js/models/conversations.js index 40d459abb..5a9617a75 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -766,9 +766,15 @@ isSecondaryDevice() { return !!this.get('secondaryStatus'); }, - async setSecondaryStatus(newStatus) { + getPrimaryDevicePubKey() { + return this.get('getPrimaryDevicePubKey') || this.id; + }, + async setSecondaryStatus(newStatus, primaryDevicePubKey) { if (this.get('secondaryStatus') !== newStatus) { - this.set({ secondaryStatus: newStatus }); + this.set({ + secondaryStatus: newStatus, + primaryDevicePubKey, + }); await window.Signal.Data.updateConversation(this.id, this.attributes, { Conversation: Whisper.Conversation, }); @@ -804,7 +810,17 @@ if (!response) { return; } - const pending = await this.getFriendRequests(direction, status); + const primaryConversation = ConversationController.get( + this.getPrimaryDevicePubKey() + ); + // Should never happen + if (!primaryConversation) { + return; + } + const pending = await primaryConversation.getFriendRequests( + direction, + status + ); await Promise.all( pending.map(async request => { if (request.hasErrors()) { @@ -815,7 +831,7 @@ await window.Signal.Data.saveMessage(request.attributes, { Message: Whisper.Message, }); - this.trigger('updateMessage', request); + primaryConversation.trigger('updateMessage', request); }) ); }, diff --git a/libloki/storage.js b/libloki/storage.js index 407d6a0fb..dd3889fba 100644 --- a/libloki/storage.js +++ b/libloki/storage.js @@ -172,7 +172,10 @@ authorisation.secondaryDevicePubKey, 'private' ); - await conversation.setSecondaryStatus(true); + await conversation.setSecondaryStatus( + true, + authorisation.primaryDevicePubKey + ); await window.Signal.Data.createOrUpdatePairingAuthorisation(authorisation); }