Fix spurious group avatar change notifications

This commit is contained in:
Fedor Indutny 2024-06-25 14:50:15 -07:00 committed by GitHub
parent 4422c4e9a1
commit 815fd77849
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -91,7 +91,6 @@ import {
conversationJobQueue, conversationJobQueue,
conversationQueueJobEnum, conversationQueueJobEnum,
} from './jobs/conversationJobQueue'; } from './jobs/conversationJobQueue';
import { groupAvatarJobQueue } from './jobs/groupAvatarJobQueue';
import { ReadStatus } from './messages/MessageReadStatus'; import { ReadStatus } from './messages/MessageReadStatus';
import { SeenStatus } from './MessageSeenStatus'; import { SeenStatus } from './MessageSeenStatus';
import { incrementMessageCounter } from './util/incrementMessageCounter'; import { incrementMessageCounter } from './util/incrementMessageCounter';
@ -3240,13 +3239,8 @@ async function updateGroup(
await appendChangeMessages(conversation, changeMessagesToSave); await appendChangeMessages(conversation, changeMessagesToSave);
} }
const { avatar: newAvatar, ...restOfAttributes } = newAttributes;
const hasAvatarChanged =
'avatar' in newAttributes &&
newAvatar?.url !== conversation.get('avatar')?.url;
conversation.set({ conversation.set({
...restOfAttributes, ...newAttributes,
active_at: activeAt, active_at: activeAt,
}); });
@ -3256,13 +3250,6 @@ async function updateGroup(
// Save these most recent updates to conversation // Save these most recent updates to conversation
await updateConversation(conversation.attributes); await updateConversation(conversation.attributes);
if (hasAvatarChanged) {
await groupAvatarJobQueue.add({
conversationId: conversation.id,
newAvatarUrl: newAvatar?.url,
});
}
} }
// Exported for testing // Exported for testing
@ -3681,7 +3668,7 @@ async function updateGroupViaPreJoinInfo({
return generateLeftGroupChanges(group); return generateLeftGroupChanges(group);
} }
const newAttributes: ConversationAttributesType = { let newAttributes: ConversationAttributesType = {
...group, ...group,
description: decryptGroupDescription( description: decryptGroupDescription(
dropNull(preJoinInfo.descriptionBytes), dropNull(preJoinInfo.descriptionBytes),
@ -3698,11 +3685,19 @@ async function updateGroupViaPreJoinInfo({
}, },
], ],
revision: dropNull(preJoinInfo.version), revision: dropNull(preJoinInfo.version),
avatar: preJoinInfo.avatar ? { url: preJoinInfo.avatar } : undefined,
temporaryMemberCount: preJoinInfo.memberCount || 1, temporaryMemberCount: preJoinInfo.memberCount || 1,
}; };
newAttributes = {
...newAttributes,
...(await applyNewAvatar(
dropNull(preJoinInfo.avatar),
newAttributes,
logId
)),
};
return { return {
newAttributes, newAttributes,
groupChangeMessages: extractDiffs({ groupChangeMessages: extractDiffs({
@ -4482,10 +4477,7 @@ function extractDiffs({
// avatar // avatar
if ( if (old.avatar?.url !== current.avatar?.url) {
Boolean(old.avatar) !== Boolean(current.avatar) ||
old.avatar?.hash !== current.avatar?.hash
) {
details.push({ details.push({
type: 'avatar', type: 'avatar',
removed: !current.avatar, removed: !current.avatar,
@ -4972,7 +4964,7 @@ async function applyGroupChange({
const MEMBER_ROLE_ENUM = Proto.Member.Role; const MEMBER_ROLE_ENUM = Proto.Member.Role;
const version = actions.version || 0; const version = actions.version || 0;
const result = { ...group }; let result = { ...group };
const newProfileKeys: Array<GroupChangeMemberType> = []; const newProfileKeys: Array<GroupChangeMemberType> = [];
const promotedAciToPniMap = new Map<AciString, PniString>(); const promotedAciToPniMap = new Map<AciString, PniString>();
@ -5259,7 +5251,10 @@ async function applyGroupChange({
// modifyAvatar?: GroupChange.Actions.ModifyAvatarAction; // modifyAvatar?: GroupChange.Actions.ModifyAvatarAction;
if (actions.modifyAvatar) { if (actions.modifyAvatar) {
const { avatar } = actions.modifyAvatar; const { avatar } = actions.modifyAvatar;
result.avatar = avatar ? { url: avatar } : undefined; result = {
...result,
...(await applyNewAvatar(dropNull(avatar), result, logId)),
};
} }
// modifyDisappearingMessagesTimer?: // modifyDisappearingMessagesTimer?:
@ -5644,7 +5639,7 @@ async function applyGroupState({
const ACCESS_ENUM = Proto.AccessControl.AccessRequired; const ACCESS_ENUM = Proto.AccessControl.AccessRequired;
const MEMBER_ROLE_ENUM = Proto.Member.Role; const MEMBER_ROLE_ENUM = Proto.Member.Role;
const version = groupState.version || 0; const version = groupState.version || 0;
const result = { ...group }; let result = { ...group };
const newProfileKeys: Array<GroupChangeMemberType> = []; const newProfileKeys: Array<GroupChangeMemberType> = [];
// Used to capture changes not already expressed in group notifications or profile keys // Used to capture changes not already expressed in group notifications or profile keys
@ -5680,11 +5675,10 @@ async function applyGroupState({
} }
// avatar // avatar
result.avatar = groupState.avatar result = {
? { ...result,
url: groupState.avatar, ...(await applyNewAvatar(dropNull(groupState.avatar), result, logId)),
} };
: undefined;
// disappearingMessagesTimer // disappearingMessagesTimer
// Note: during decryption, disappearingMessageTimer becomes a GroupAttributeBlob // Note: during decryption, disappearingMessageTimer becomes a GroupAttributeBlob