[Glitch] Fix follow notifications from streaming being grouped
Port 1be55ce244 to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
			
			
This commit is contained in:
		
							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,6 +206,7 @@ function processNewNotification(
 | 
				
			||||||
  groups: NotificationGroupsState['groups'],
 | 
					  groups: NotificationGroupsState['groups'],
 | 
				
			||||||
  notification: ApiNotificationJSON,
 | 
					  notification: ApiNotificationJSON,
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
 | 
					  if (shouldGroupNotificationType(notification.type)) {
 | 
				
			||||||
    const existingGroupIndex = groups.findIndex(
 | 
					    const existingGroupIndex = groups.findIndex(
 | 
				
			||||||
      (group) =>
 | 
					      (group) =>
 | 
				
			||||||
        group.type !== 'gap' && group.group_key === notification.group_key,
 | 
					        group.type !== 'gap' && group.group_key === notification.group_key,
 | 
				
			||||||
| 
						 | 
					@ -240,12 +242,15 @@ function processNewNotification(
 | 
				
			||||||
        mergeGapsAround(groups, existingGroupIndex);
 | 
					        mergeGapsAround(groups, existingGroupIndex);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        groups.unshift(existingGroup);
 | 
					        groups.unshift(existingGroup);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
  } else {
 | 
					    }
 | 
				
			||||||
    // Create a new group
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // We have not found an existing group, create a new one
 | 
				
			||||||
  groups.unshift(createNotificationGroupFromNotificationJSON(notification));
 | 
					  groups.unshift(createNotificationGroupFromNotificationJSON(notification));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
function trimNotifications(state: NotificationGroupsState) {
 | 
					function trimNotifications(state: NotificationGroupsState) {
 | 
				
			||||||
  if (state.scrolledToTop && state.groups.length > NOTIFICATIONS_TRIM_LIMIT) {
 | 
					  if (state.scrolledToTop && state.groups.length > NOTIFICATIONS_TRIM_LIMIT) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue