diff --git a/app/soapbox/actions/notifications.ts b/app/soapbox/actions/notifications.ts index 79994bde5..4edd76c22 100644 --- a/app/soapbox/actions/notifications.ts +++ b/app/soapbox/actions/notifications.ts @@ -1,5 +1,4 @@ import { - List as ImmutableList, Map as ImmutableMap, } from 'immutable'; import IntlMessageFormat from 'intl-messageformat'; @@ -12,6 +11,7 @@ import { getFilters, regexFromFilters } from 'soapbox/selectors'; import { isLoggedIn } from 'soapbox/utils/auth'; import { getFeatures, parseVersion, PLEROMA } from 'soapbox/utils/features'; import { unescapeHTML } from 'soapbox/utils/html'; +import { NOTIFICATION_TYPES } from 'soapbox/utils/notification'; import { joinPublicPath } from 'soapbox/utils/static'; import { fetchRelationships } from './accounts'; @@ -168,11 +168,8 @@ const dequeueNotifications = () => dispatch(markReadNotifications()); }; -// const excludeTypesFromSettings = (getState: () => RootState) => (getSettings(getState()).getIn(['notifications', 'shows']) as ImmutableMap).filter(enabled => !enabled).keySeq().toJS(); - const excludeTypesFromFilter = (filter: string) => { - const allTypes = ImmutableList(['follow', 'follow_request', 'favourite', 'reblog', 'mention', 'status', 'poll', 'move', 'pleroma:emoji_reaction']); - return allTypes.filterNot(item => item === filter).toJS(); + return NOTIFICATION_TYPES.filter(item => item !== filter); }; const noOp = () => new Promise(f => f(undefined)); @@ -182,6 +179,7 @@ const expandNotifications = ({ maxId }: Record = {}, done: () => an if (!isLoggedIn(getState)) return dispatch(noOp); const state = getState(); + const features = getFeatures(state.instance); const activeFilter = getSettings(state).getIn(['notifications', 'quickFilter', 'active']) as string; const notifications = state.notifications; const isLoadingMore = !!maxId; @@ -195,10 +193,11 @@ const expandNotifications = ({ maxId }: Record = {}, done: () => an max_id: maxId, }; - if (activeFilter !== 'all') { - const instance = state.instance; - const features = getFeatures(instance); - + if (activeFilter === 'all') { + if (features.notificationsIncludeTypes) { + params.types = NOTIFICATION_TYPES; + } + } else { if (features.notificationsIncludeTypes) { params.types = [activeFilter]; } else { diff --git a/app/soapbox/features/notifications/components/notification.tsx b/app/soapbox/features/notifications/components/notification.tsx index e1fa87c5a..1871b3a89 100644 --- a/app/soapbox/features/notifications/components/notification.tsx +++ b/app/soapbox/features/notifications/components/notification.tsx @@ -268,7 +268,7 @@ const Notification: React.FC = (props) => { }; const renderContent = () => { - switch (type) { + switch (type as NotificationType) { case 'follow': case 'user_approved': return account && typeof account === 'object' ? ( diff --git a/app/soapbox/reducers/notifications.js b/app/soapbox/reducers/notifications.js index d7697d4dd..4d5dd9921 100644 --- a/app/soapbox/reducers/notifications.js +++ b/app/soapbox/reducers/notifications.js @@ -5,6 +5,7 @@ import { } from 'immutable'; import { normalizeNotification } from 'soapbox/normalizers/notification'; +import { validType } from 'soapbox/utils/notification'; import { ACCOUNT_BLOCK_SUCCESS, @@ -67,6 +68,11 @@ const fixNotification = notification => { const isValid = notification => { try { + // Ensure the notification is a known type + if (!validType(notification.type)) { + return false; + } + // https://gitlab.com/soapbox-pub/soapbox/-/issues/424 if (!notification.account.id) { return false;