From 20d728b4dd98541e9008fdc44cb97fbc544b996b Mon Sep 17 00:00:00 2001 From: automated-signal <37887102+automated-signal@users.noreply.github.com> Date: Tue, 25 Jun 2024 17:19:58 -0500 Subject: [PATCH] Fix spurious group avatar change notifications Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> --- ts/groups.ts | 50 ++++++++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/ts/groups.ts b/ts/groups.ts index 221ae324644..d0c5cdfad05 100644 --- a/ts/groups.ts +++ b/ts/groups.ts @@ -91,7 +91,6 @@ import { conversationJobQueue, conversationQueueJobEnum, } from './jobs/conversationJobQueue'; -import { groupAvatarJobQueue } from './jobs/groupAvatarJobQueue'; import { ReadStatus } from './messages/MessageReadStatus'; import { SeenStatus } from './MessageSeenStatus'; import { incrementMessageCounter } from './util/incrementMessageCounter'; @@ -3240,13 +3239,8 @@ async function updateGroup( await appendChangeMessages(conversation, changeMessagesToSave); } - const { avatar: newAvatar, ...restOfAttributes } = newAttributes; - const hasAvatarChanged = - 'avatar' in newAttributes && - newAvatar?.url !== conversation.get('avatar')?.url; - conversation.set({ - ...restOfAttributes, + ...newAttributes, active_at: activeAt, }); @@ -3256,13 +3250,6 @@ async function updateGroup( // Save these most recent updates to conversation await updateConversation(conversation.attributes); - - if (hasAvatarChanged) { - await groupAvatarJobQueue.add({ - conversationId: conversation.id, - newAvatarUrl: newAvatar?.url, - }); - } } // Exported for testing @@ -3681,7 +3668,7 @@ async function updateGroupViaPreJoinInfo({ return generateLeftGroupChanges(group); } - const newAttributes: ConversationAttributesType = { + let newAttributes: ConversationAttributesType = { ...group, description: decryptGroupDescription( dropNull(preJoinInfo.descriptionBytes), @@ -3698,11 +3685,19 @@ async function updateGroupViaPreJoinInfo({ }, ], revision: dropNull(preJoinInfo.version), - avatar: preJoinInfo.avatar ? { url: preJoinInfo.avatar } : undefined, temporaryMemberCount: preJoinInfo.memberCount || 1, }; + newAttributes = { + ...newAttributes, + ...(await applyNewAvatar( + dropNull(preJoinInfo.avatar), + newAttributes, + logId + )), + }; + return { newAttributes, groupChangeMessages: extractDiffs({ @@ -4482,10 +4477,7 @@ function extractDiffs({ // avatar - if ( - Boolean(old.avatar) !== Boolean(current.avatar) || - old.avatar?.hash !== current.avatar?.hash - ) { + if (old.avatar?.url !== current.avatar?.url) { details.push({ type: 'avatar', removed: !current.avatar, @@ -4972,7 +4964,7 @@ async function applyGroupChange({ const MEMBER_ROLE_ENUM = Proto.Member.Role; const version = actions.version || 0; - const result = { ...group }; + let result = { ...group }; const newProfileKeys: Array = []; const promotedAciToPniMap = new Map(); @@ -5259,7 +5251,10 @@ async function applyGroupChange({ // modifyAvatar?: GroupChange.Actions.ModifyAvatarAction; if (actions.modifyAvatar) { const { avatar } = actions.modifyAvatar; - result.avatar = avatar ? { url: avatar } : undefined; + result = { + ...result, + ...(await applyNewAvatar(dropNull(avatar), result, logId)), + }; } // modifyDisappearingMessagesTimer?: @@ -5644,7 +5639,7 @@ async function applyGroupState({ const ACCESS_ENUM = Proto.AccessControl.AccessRequired; const MEMBER_ROLE_ENUM = Proto.Member.Role; const version = groupState.version || 0; - const result = { ...group }; + let result = { ...group }; const newProfileKeys: Array = []; // Used to capture changes not already expressed in group notifications or profile keys @@ -5680,11 +5675,10 @@ async function applyGroupState({ } // avatar - result.avatar = groupState.avatar - ? { - url: groupState.avatar, - } - : undefined; + result = { + ...result, + ...(await applyNewAvatar(dropNull(groupState.avatar), result, logId)), + }; // disappearingMessagesTimer // Note: during decryption, disappearingMessageTimer becomes a GroupAttributeBlob