Skip to content

Commit

Permalink
Allowlist groupable notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
cheeaun committed Nov 7, 2024
1 parent 35fa94b commit a1a4b01
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/utils/group-notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -85,16 +89,18 @@ 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';
}
// 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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit a1a4b01

Please sign in to comment.