1
0

[Glitch] Fix all notification types being stored without filtering when polling

Port fab29ebbe8 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
Claire 2024-09-04 15:28:16 +02:00
parent 5a55180b95
commit 1d86377ba9

View File

@ -18,7 +18,7 @@ import {
selectSettingsNotificationsQuickFilterActive, selectSettingsNotificationsQuickFilterActive,
selectSettingsNotificationsShows, selectSettingsNotificationsShows,
} from 'flavours/glitch/selectors/settings'; } from 'flavours/glitch/selectors/settings';
import type { AppDispatch } from 'flavours/glitch/store'; import type { AppDispatch, RootState } from 'flavours/glitch/store';
import { import {
createAppAsyncThunk, createAppAsyncThunk,
createDataLoadingThunk, createDataLoadingThunk,
@ -32,6 +32,14 @@ function excludeAllTypesExcept(filter: string) {
return allNotificationTypes.filter((item) => item !== filter); return allNotificationTypes.filter((item) => item !== filter);
} }
function getExcludedTypes(state: RootState) {
const activeFilter = selectSettingsNotificationsQuickFilterActive(state);
return activeFilter === 'all'
? selectSettingsNotificationsExcludedTypes(state)
: excludeAllTypesExcept(activeFilter);
}
function dispatchAssociatedRecords( function dispatchAssociatedRecords(
dispatch: AppDispatch, dispatch: AppDispatch,
notifications: ApiNotificationGroupJSON[] | ApiNotificationJSON[], notifications: ApiNotificationGroupJSON[] | ApiNotificationJSON[],
@ -62,17 +70,8 @@ function dispatchAssociatedRecords(
export const fetchNotifications = createDataLoadingThunk( export const fetchNotifications = createDataLoadingThunk(
'notificationGroups/fetch', 'notificationGroups/fetch',
async (_params, { getState }) => { async (_params, { getState }) =>
const activeFilter = apiFetchNotifications({ exclude_types: getExcludedTypes(getState()) }),
selectSettingsNotificationsQuickFilterActive(getState());
return apiFetchNotifications({
exclude_types:
activeFilter === 'all'
? selectSettingsNotificationsExcludedTypes(getState())
: excludeAllTypesExcept(activeFilter),
});
},
({ notifications, accounts, statuses }, { dispatch }) => { ({ notifications, accounts, statuses }, { dispatch }) => {
dispatch(importFetchedAccounts(accounts)); dispatch(importFetchedAccounts(accounts));
dispatch(importFetchedStatuses(statuses)); dispatch(importFetchedStatuses(statuses));
@ -92,9 +91,11 @@ export const fetchNotifications = createDataLoadingThunk(
export const fetchNotificationsGap = createDataLoadingThunk( export const fetchNotificationsGap = createDataLoadingThunk(
'notificationGroups/fetchGap', 'notificationGroups/fetchGap',
async (params: { gap: NotificationGap }) => async (params: { gap: NotificationGap }, { getState }) =>
apiFetchNotifications({ max_id: params.gap.maxId }), apiFetchNotifications({
max_id: params.gap.maxId,
exclude_types: getExcludedTypes(getState()),
}),
({ notifications, accounts, statuses }, { dispatch }) => { ({ notifications, accounts, statuses }, { dispatch }) => {
dispatch(importFetchedAccounts(accounts)); dispatch(importFetchedAccounts(accounts));
dispatch(importFetchedStatuses(statuses)); dispatch(importFetchedStatuses(statuses));
@ -109,6 +110,7 @@ export const pollRecentNotifications = createDataLoadingThunk(
async (_params, { getState }) => { async (_params, { getState }) => {
return apiFetchNotifications({ return apiFetchNotifications({
max_id: undefined, max_id: undefined,
exclude_types: getExcludedTypes(getState()),
// In slow mode, we don't want to include notifications that duplicate the already-displayed ones // In slow mode, we don't want to include notifications that duplicate the already-displayed ones
since_id: usePendingItems since_id: usePendingItems
? getState().notificationGroups.groups.find( ? getState().notificationGroups.groups.find(
@ -183,7 +185,6 @@ export const setNotificationsFilter = createAppAsyncThunk(
path: ['notifications', 'quickFilter', 'active'], path: ['notifications', 'quickFilter', 'active'],
value: filterType, value: filterType,
}); });
// dispatch(expandNotifications({ forceLoad: true }));
void dispatch(fetchNotifications()); void dispatch(fetchNotifications());
dispatch(saveSettings()); dispatch(saveSettings());
}, },