From a1a4b01ace2fac0aaf7cbb05ea4ebbcb8e6db0a7 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Thu, 7 Nov 2024 16:13:50 +0800 Subject: [PATCH] Allowlist groupable notifications --- src/utils/group-notifications.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/utils/group-notifications.js b/src/utils/group-notifications.js index 0d307ead..4017a8bd 100644 --- a/src/utils/group-notifications.js +++ b/src/utils/group-notifications.js @@ -9,6 +9,10 @@ const notificationTypeKeys = { poll: ['status'], update: ['status'], }; + +const GROUP_TYPES = ['favourite', 'reblog', 'follow']; +const groupable = (type) => GROUP_TYPES.includes(type); + export function fixNotifications(notifications) { return notifications.filter((notification) => { const { type, id, createdAt } = notification; @@ -85,8 +89,8 @@ export function groupNotifications2(groupNotifications) { } = gn; const date = createdAt ? new Date(createdAt).toLocaleDateString() : ''; let virtualType = type; - const sameCount = - notificationsCount > 0 && notificationsCount === sampleAccounts?.length; + // const sameCount = + notificationsCount > 0 && notificationsCount === sampleAccounts?.length; // if (sameCount && (type === 'favourite' || type === 'reblog')) { if (type === 'favourite' || type === 'reblog') { virtualType = 'favourite+reblog'; @@ -94,7 +98,9 @@ export function groupNotifications2(groupNotifications) { // const key = `${status?.id}-${virtualType}-${date}-${sameCount ? 1 : 0}`; const key = `${status?.id}-${virtualType}-${date}`; const mappedNotification = notificationsMap[key]; - if (mappedNotification) { + if (!groupable(type)) { + newGroupNotifications1.push(gn); + } else if (mappedNotification) { // Merge sampleAccounts + merge _types sampleAccounts.forEach((a) => { const mappedAccount = mappedNotification.sampleAccounts.find( @@ -199,7 +205,7 @@ export default function groupNotifications(notifications) { } const key = `${status?.id}-${virtualType}-${date}`; const mappedNotification = notificationsMap[key]; - if (virtualType === 'follow_request') { + if (!groupable(type)) { cleanNotifications[j++] = notification; } else if (mappedNotification?.account) { const mappedAccount = mappedNotification._accounts.find(