From 15b8600e2543ea257934df1e6329404327ecfba1 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Tue, 7 Jul 2020 13:30:25 +1000 Subject: [PATCH] fix display name and avatar not being updated when message from secondary --- js/background.js | 2 -- ts/receiver/dataMessage.ts | 20 ++++++++++++++------ ts/receiver/queuedJob.ts | 15 +++++++++------ ts/session/protocols/SessionProtocol.ts | 2 -- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/js/background.js b/js/background.js index 673bcc590..a09e95962 100644 --- a/js/background.js +++ b/js/background.js @@ -644,8 +644,6 @@ confirm: () => {}, }; - - const recipients = _.union(convo.get('members'), members); await window.NewReceiver.onGroupReceived(ev); diff --git a/ts/receiver/dataMessage.ts b/ts/receiver/dataMessage.ts index 06116b058..d01ae3c46 100644 --- a/ts/receiver/dataMessage.ts +++ b/ts/receiver/dataMessage.ts @@ -70,12 +70,20 @@ export async function updateProfile( newProfile.avatar = null; } - await conversation.setLokiProfile(newProfile); - - if (conversation.isSecondaryDevice()) { - const primaryConversation = await conversation.getPrimaryConversation(); - await primaryConversation.setLokiProfile(newProfile); - } + const allUserDevices = await MultiDeviceProtocol.getAllDevices( + conversation.id + ); + const { ConversationController } = window; + + await Promise.all( + allUserDevices.map(async device => { + const conv = await ConversationController.getOrCreateAndWait( + device.key, + 'private' + ); + await conv.setLokiProfile(newProfile); + }) + ); } function cleanAttachment(attachment: any) { diff --git a/ts/receiver/queuedJob.ts b/ts/receiver/queuedJob.ts index 0cdf57a9c..34493e653 100644 --- a/ts/receiver/queuedJob.ts +++ b/ts/receiver/queuedJob.ts @@ -13,18 +13,15 @@ async function handleGroups( group: any, source: any ): Promise { - const textsecure = window.textsecure; const GROUP_TYPES = SignalService.GroupContext.Type; - // TODO: this should be primary device id! - const ourNumber = textsecure.storage.user.getNumber(); - let groupUpdate = null; // conversation attributes const attributes: any = { type: 'group', groupId: group.id, + ...conversation.attributes, }; const oldMembers = conversation.get('members'); @@ -54,15 +51,21 @@ async function handleGroups( // Check if anyone got kicked: const removedMembers = _.difference(oldMembers, attributes.members); + const isOurDeviceMap = await Promise.all( + removedMembers.map(async member => + MultiDeviceProtocol.isOurDevice(member) + ) + ); + const ourDeviceWasRemoved = isOurDeviceMap.includes(true); - if (removedMembers.includes(ourNumber)) { + if (ourDeviceWasRemoved) { groupUpdate.kicked = 'You'; attributes.isKickedFromGroup = true; } else if (removedMembers.length) { groupUpdate.kicked = removedMembers; } } else if (group.type === GROUP_TYPES.QUIT) { - if (source === ourNumber) { + if (await MultiDeviceProtocol.isOurDevice(source)) { attributes.left = true; groupUpdate = { left: 'You' }; } else { diff --git a/ts/session/protocols/SessionProtocol.ts b/ts/session/protocols/SessionProtocol.ts index 0fe52f915..45b3673f6 100644 --- a/ts/session/protocols/SessionProtocol.ts +++ b/ts/session/protocols/SessionProtocol.ts @@ -105,8 +105,6 @@ export class SessionProtocol { public static async sendSessionRequestIfNeeded( pubkey: PubKey ): Promise { - const { ConversationController } = window; - if ( (await SessionProtocol.hasSession(pubkey)) || (await SessionProtocol.hasSentSessionRequest(pubkey))