[Glitch] Fix follow notifications from streaming being grouped
Port 1be55ce244
to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
pull/2867/head
parent
b28ce2424c
commit
8572fa1452
|
@ -70,6 +70,10 @@ function dispatchAssociatedRecords(
|
||||||
|
|
||||||
const supportedGroupedNotificationTypes = ['favourite', 'reblog'];
|
const supportedGroupedNotificationTypes = ['favourite', 'reblog'];
|
||||||
|
|
||||||
|
export function shouldGroupNotificationType(type: string) {
|
||||||
|
return supportedGroupedNotificationTypes.includes(type);
|
||||||
|
}
|
||||||
|
|
||||||
export const fetchNotifications = createDataLoadingThunk(
|
export const fetchNotifications = createDataLoadingThunk(
|
||||||
'notificationGroups/fetch',
|
'notificationGroups/fetch',
|
||||||
async (_params, { getState }) =>
|
async (_params, { getState }) =>
|
||||||
|
|
|
@ -21,6 +21,7 @@ import {
|
||||||
unmountNotifications,
|
unmountNotifications,
|
||||||
refreshStaleNotificationGroups,
|
refreshStaleNotificationGroups,
|
||||||
pollRecentNotifications,
|
pollRecentNotifications,
|
||||||
|
shouldGroupNotificationType,
|
||||||
} from 'flavours/glitch/actions/notification_groups';
|
} from 'flavours/glitch/actions/notification_groups';
|
||||||
import {
|
import {
|
||||||
disconnectTimeline,
|
disconnectTimeline,
|
||||||
|
@ -205,46 +206,50 @@ function processNewNotification(
|
||||||
groups: NotificationGroupsState['groups'],
|
groups: NotificationGroupsState['groups'],
|
||||||
notification: ApiNotificationJSON,
|
notification: ApiNotificationJSON,
|
||||||
) {
|
) {
|
||||||
const existingGroupIndex = groups.findIndex(
|
if (shouldGroupNotificationType(notification.type)) {
|
||||||
(group) =>
|
const existingGroupIndex = groups.findIndex(
|
||||||
group.type !== 'gap' && group.group_key === notification.group_key,
|
(group) =>
|
||||||
);
|
group.type !== 'gap' && group.group_key === notification.group_key,
|
||||||
|
);
|
||||||
|
|
||||||
// In any case, we are going to add a group at the top
|
// In any case, we are going to add a group at the top
|
||||||
// If there is currently a gap at the top, now is the time to update it
|
// If there is currently a gap at the top, now is the time to update it
|
||||||
if (groups.length > 0 && groups[0]?.type === 'gap') {
|
if (groups.length > 0 && groups[0]?.type === 'gap') {
|
||||||
groups[0].maxId = notification.id;
|
groups[0].maxId = notification.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (existingGroupIndex > -1) {
|
if (existingGroupIndex > -1) {
|
||||||
const existingGroup = groups[existingGroupIndex];
|
const existingGroup = groups[existingGroupIndex];
|
||||||
|
|
||||||
if (
|
if (
|
||||||
existingGroup &&
|
existingGroup &&
|
||||||
existingGroup.type !== 'gap' &&
|
existingGroup.type !== 'gap' &&
|
||||||
!existingGroup.sampleAccountIds.includes(notification.account.id) // This can happen for example if you like, then unlike, then like again the same post
|
!existingGroup.sampleAccountIds.includes(notification.account.id) // This can happen for example if you like, then unlike, then like again the same post
|
||||||
) {
|
) {
|
||||||
// Update the existing group
|
// Update the existing group
|
||||||
if (
|
if (
|
||||||
existingGroup.sampleAccountIds.unshift(notification.account.id) >
|
existingGroup.sampleAccountIds.unshift(notification.account.id) >
|
||||||
NOTIFICATIONS_GROUP_MAX_AVATARS
|
NOTIFICATIONS_GROUP_MAX_AVATARS
|
||||||
)
|
)
|
||||||
existingGroup.sampleAccountIds.pop();
|
existingGroup.sampleAccountIds.pop();
|
||||||
|
|
||||||
existingGroup.most_recent_notification_id = notification.id;
|
existingGroup.most_recent_notification_id = notification.id;
|
||||||
existingGroup.page_max_id = notification.id;
|
existingGroup.page_max_id = notification.id;
|
||||||
existingGroup.latest_page_notification_at = notification.created_at;
|
existingGroup.latest_page_notification_at = notification.created_at;
|
||||||
existingGroup.notifications_count += 1;
|
existingGroup.notifications_count += 1;
|
||||||
|
|
||||||
groups.splice(existingGroupIndex, 1);
|
groups.splice(existingGroupIndex, 1);
|
||||||
mergeGapsAround(groups, existingGroupIndex);
|
mergeGapsAround(groups, existingGroupIndex);
|
||||||
|
|
||||||
groups.unshift(existingGroup);
|
groups.unshift(existingGroup);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// Create a new group
|
|
||||||
groups.unshift(createNotificationGroupFromNotificationJSON(notification));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We have not found an existing group, create a new one
|
||||||
|
groups.unshift(createNotificationGroupFromNotificationJSON(notification));
|
||||||
}
|
}
|
||||||
|
|
||||||
function trimNotifications(state: NotificationGroupsState) {
|
function trimNotifications(state: NotificationGroupsState) {
|
||||||
|
|
Loading…
Reference in New Issue