From 2c052a65a26e9479d3f77922338c2088d43e2c6e Mon Sep 17 00:00:00 2001 From: sachaaaaa Date: Tue, 27 Aug 2019 14:23:00 +1000 Subject: [PATCH] Display incoming messages in the primary device conversation --- js/background.js | 22 ++++++++++++++++++++-- js/delivery_receipts.js | 12 +++++++++++- js/models/messages.js | 11 +++++++++-- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/js/background.js b/js/background.js index 29dbf195e..85a1c1e39 100644 --- a/js/background.js +++ b/js/background.js @@ -1016,7 +1016,7 @@ ev.confirm(); } - function onTyping(ev) { + async function onTyping(ev) { const { typing, sender, senderDevice } = ev; const { groupId, started } = typing || {}; @@ -1025,7 +1025,17 @@ return; } - const conversation = ConversationController.get(groupId || sender); + let primaryDevice = null; + const authorisation = await window.libloki.storage.getGrantAuthorisationForSecondaryPubKey( + sender + ); + if (authorisation) { + primaryDevice = authorisation.primaryDevicePubKey; + } + + const conversation = ConversationController.get( + groupId || primaryDevice || sender + ); if (conversation) { conversation.notifyTyping({ @@ -1239,6 +1249,14 @@ const messageDescriptor = getMessageDescriptor(data); + // Funnel messages to primary device conversation if multi-device + const authorisation = await window.libloki.storage.getGrantAuthorisationForSecondaryPubKey( + messageDescriptor.id + ); + if (authorisation) { + messageDescriptor.id = authorisation.primaryDevicePubKey; + } + const { PROFILE_KEY_UPDATE } = textsecure.protobuf.DataMessage.Flags; // eslint-disable-next-line no-bitwise const isProfileUpdate = Boolean(data.message.flags & PROFILE_KEY_UPDATE); diff --git a/js/delivery_receipts.js b/js/delivery_receipts.js index ea52a6822..c2fa998ef 100644 --- a/js/delivery_receipts.js +++ b/js/delivery_receipts.js @@ -3,7 +3,8 @@ Whisper, ConversationController, MessageController, - _ + _, + libloki, */ /* eslint-disable more/no-then */ @@ -34,6 +35,15 @@ if (messages.length === 0) { return null; } + + const authorisation = await libloki.storage.getGrantAuthorisationForSecondaryPubKey( + source + ); + if (authorisation) { + // eslint-disable-next-line no-param-reassign + source = authorisation.primaryDevicePubKey; + } + const message = messages.find( item => !item.isIncoming() && source === item.get('conversationId') ); diff --git a/js/models/messages.js b/js/models/messages.js index 8f91658a8..33c5bc7df 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -10,7 +10,8 @@ Signal, textsecure, Whisper, - clipboard + clipboard, + libloki, */ /* eslint-disable more/no-then */ @@ -1697,7 +1698,7 @@ return message; }, - handleDataMessage(initialMessage, confirm) { + async handleDataMessage(initialMessage, confirm) { // This function is called from the background script in a few scenarios: // 1. on an incoming message // 2. on a sent message sync'd from another device @@ -1707,9 +1708,15 @@ const source = message.get('source'); const type = message.get('type'); let conversationId = message.get('conversationId'); + const authorisation = await libloki.storage.getGrantAuthorisationForSecondaryPubKey( + source + ); if (initialMessage.group) { conversationId = initialMessage.group.id; + } else if (authorisation) { + conversationId = authorisation.primaryDevicePubKey; } + const GROUP_TYPES = textsecure.protobuf.GroupContext.Type; const conversation = ConversationController.get(conversationId);