From 08ad913105cc2478e3d0c2ae31cacc7b55b078c7 Mon Sep 17 00:00:00 2001 From: Beaudan Brown Date: Mon, 28 Oct 2019 12:03:09 +1100 Subject: [PATCH] Add explicit isSecondary flag to conversation list items so they can remain hidden in the menu after they become friends etc --- _locales/en/messages.json | 6 ++++++ js/models/conversations.js | 12 ++++++++++++ js/views/conversation_view.js | 3 +++ js/views/inbox_view.js | 4 +++- libloki/storage.js | 13 ++++++++++--- libtextsecure/message_receiver.js | 1 + ts/components/ConversationListItem.tsx | 1 + ts/components/LeftPane.tsx | 10 +++++++++- 8 files changed, 45 insertions(+), 5 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 49b950e95..d31c1dd9e 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1008,6 +1008,12 @@ "message": "Send a message", "description": "Placeholder text in the message entry field" }, + "sendMessageDisabledSecondary": { + "message": + "This pubkey belongs to a secondary device. You should never see this message", + "description": + "Placeholder text in the message entry field when it is disabled because a secondary device conversation is visible" + }, "sendMessageDisabled": { "message": "Waiting for friend request approval", "description": diff --git a/js/models/conversations.js b/js/models/conversations.js index 35ecae10c..25c62b88f 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -469,6 +469,7 @@ mentionedUs: this.get('mentionedUs') || false, showFriendRequestIndicator: this.isPendingFriendRequest(), isBlocked: this.isBlocked(), + isSecondary: !!this.get('secondaryStatus'), phoneNumber: format(this.id, { ourRegionCode: regionCode, @@ -691,6 +692,17 @@ throw new Error('Invalid friend request state'); } }, + isSecondaryDevice() { + return !!this.get('secondaryStatus'); + }, + async setSecondaryStatus(newStatus) { + if (this.get('secondaryStatus') !== newStatus) { + this.set({ secondaryStatus: newStatus }); + await window.Signal.Data.updateConversation(this.id, this.attributes, { + Conversation: Whisper.Conversation, + }); + } + }, async setFriendRequestStatus(newStatus) { // Ensure that the new status is a valid FriendStatusEnum value if (!(newStatus in Object.values(FriendRequestStatusEnum))) { diff --git a/js/views/conversation_view.js b/js/views/conversation_view.js index b643b4a43..e78001e9f 100644 --- a/js/views/conversation_view.js +++ b/js/views/conversation_view.js @@ -436,6 +436,9 @@ case 'disabled': placeholder = i18n('sendMessageDisabled'); break; + case 'secondary': + placeholder = i18n('sendMessageDisabledSecondary'); + break; default: placeholder = i18n('sendMessage'); break; diff --git a/js/views/inbox_view.js b/js/views/inbox_view.js index 9fa7c703b..3fb850290 100644 --- a/js/views/inbox_view.js +++ b/js/views/inbox_view.js @@ -155,7 +155,9 @@ }, user: { regionCode: window.storage.get('regionCode'), - ourNumber: textsecure.storage.user.getNumber(), + ourNumber: + window.storage.get('primaryDevicePubKey') || + textsecure.storage.user.getNumber(), isSecondaryDevice: !!window.storage.get('isSecondaryDevice'), i18n: window.i18n, }, diff --git a/libloki/storage.js b/libloki/storage.js index 733d3df92..6dfbfd116 100644 --- a/libloki/storage.js +++ b/libloki/storage.js @@ -1,4 +1,5 @@ -/* global window, libsignal, textsecure, Signal, lokiFileServerAPI */ +/* global window, libsignal, textsecure, + Signal, lokiFileServerAPI, ConversationController */ // eslint-disable-next-line func-names (function() { @@ -149,8 +150,14 @@ ); } - function savePairingAuthorisation(authorisation) { - return window.Signal.Data.createOrUpdatePairingAuthorisation(authorisation); + async function savePairingAuthorisation(authorisation) { + // Ensure that we have a conversation for all the devices + const conversation = await ConversationController.getOrCreateAndWait( + authorisation.secondaryDevicePubKey, + 'private' + ); + await conversation.setSecondaryStatus(true); + await window.Signal.Data.createOrUpdatePairingAuthorisation(authorisation); } function removePairingAuthorisationForSecondaryPubKey(pubKey) { diff --git a/libtextsecure/message_receiver.js b/libtextsecure/message_receiver.js index 44d546e4f..1379d560f 100644 --- a/libtextsecure/message_receiver.js +++ b/libtextsecure/message_receiver.js @@ -1107,6 +1107,7 @@ MessageReceiver.prototype.extend({ // along with each friend request. window.storage.remove('secondaryDeviceStatus'); window.storage.put('isSecondaryDevice', true); + window.storage.put('primaryDevicePubKey', primaryDevicePubKey); Whisper.events.trigger('secondaryDeviceRegistration'); // Update profile name if (dataMessage && dataMessage.profile) { diff --git a/ts/components/ConversationListItem.tsx b/ts/components/ConversationListItem.tsx index 8a973420d..4e14a7350 100644 --- a/ts/components/ConversationListItem.tsx +++ b/ts/components/ConversationListItem.tsx @@ -41,6 +41,7 @@ export type PropsData = { isOnline?: boolean; hasNickname?: boolean; isFriendItem?: boolean; + isSecondary?: boolean; }; type PropsHousekeeping = { diff --git a/ts/components/LeftPane.tsx b/ts/components/LeftPane.tsx index 6541c8601..df9be954c 100644 --- a/ts/components/LeftPane.tsx +++ b/ts/components/LeftPane.tsx @@ -55,7 +55,15 @@ export class LeftPane extends React.Component { const { conversations, friends } = this.props; const { currentTab } = this.state; - return currentTab === 'conversations' ? conversations : friends; + let conversationList = + currentTab === 'conversations' ? conversations : friends; + if (conversationList !== undefined) { + conversationList = conversationList.filter( + conversation => !conversation.isSecondary + ); + } + + return conversationList; } public renderTabs(): JSX.Element {