From 10094597608e1dba000fd315518b839ae5a680fb Mon Sep 17 00:00:00 2001 From: Claire Date: Thu, 21 Nov 2024 11:05:39 +0100 Subject: [PATCH] Fix duplicate notifications in notification groups when using slow mode Fixes #32993 --- app/javascript/mastodon/models/notification_group.ts | 8 ++++++++ .../mastodon/reducers/notification_groups.ts | 11 +++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/javascript/mastodon/models/notification_group.ts b/app/javascript/mastodon/models/notification_group.ts index 1195fd73e4..d98e755aa2 100644 --- a/app/javascript/mastodon/models/notification_group.ts +++ b/app/javascript/mastodon/models/notification_group.ts @@ -17,6 +17,7 @@ export const NOTIFICATIONS_GROUP_MAX_AVATARS = 8; interface BaseNotificationGroup extends Omit { sampleAccountIds: string[]; + partial: boolean; } interface BaseNotificationWithStatus @@ -142,6 +143,7 @@ export function createNotificationGroupFromJSON( return { statusId: statusId ?? undefined, sampleAccountIds, + partial: false, ...groupWithoutStatus, }; } @@ -150,12 +152,14 @@ export function createNotificationGroupFromJSON( return { report: createReportFromJSON(report), sampleAccountIds, + partial: false, ...groupWithoutTargetAccount, }; } case 'severed_relationships': return { ...group, + partial: false, event: createAccountRelationshipSeveranceEventFromJSON(group.event), sampleAccountIds, }; @@ -163,6 +167,7 @@ export function createNotificationGroupFromJSON( const { moderation_warning, ...groupWithoutModerationWarning } = group; return { ...groupWithoutModerationWarning, + partial: false, moderationWarning: createAccountWarningFromJSON(moderation_warning), sampleAccountIds, }; @@ -171,6 +176,7 @@ export function createNotificationGroupFromJSON( const { annual_report, ...groupWithoutAnnualReport } = group; return { ...groupWithoutAnnualReport, + partial: false, annualReport: createAnnualReportEventFromJSON(annual_report), sampleAccountIds, }; @@ -178,6 +184,7 @@ export function createNotificationGroupFromJSON( default: return { sampleAccountIds, + partial: false, ...group, }; } @@ -194,6 +201,7 @@ export function createNotificationGroupFromNotificationJSON( page_min_id: notification.id, page_max_id: notification.id, latest_page_notification_at: notification.created_at, + partial: true, }; switch (notification.type) { diff --git a/app/javascript/mastodon/reducers/notification_groups.ts b/app/javascript/mastodon/reducers/notification_groups.ts index 7a165f5fec..d43714beb7 100644 --- a/app/javascript/mastodon/reducers/notification_groups.ts +++ b/app/javascript/mastodon/reducers/notification_groups.ts @@ -534,10 +534,13 @@ export const notificationGroupsReducer = createReducer( if (existingGroupIndex > -1) { const existingGroup = state.groups[existingGroupIndex]; if (existingGroup && existingGroup.type !== 'gap') { - group.notifications_count += existingGroup.notifications_count; - group.sampleAccountIds = group.sampleAccountIds - .concat(existingGroup.sampleAccountIds) - .slice(0, NOTIFICATIONS_GROUP_MAX_AVATARS); + if (group.partial) { + group.notifications_count += + existingGroup.notifications_count; + group.sampleAccountIds = group.sampleAccountIds + .concat(existingGroup.sampleAccountIds) + .slice(0, NOTIFICATIONS_GROUP_MAX_AVATARS); + } state.groups.splice(existingGroupIndex, 1); } }