From a9aae8fbe8d1b359aff4a63ef0946b793ab97fbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Mon, 1 Aug 2022 18:56:11 +0200 Subject: [PATCH] Use `types` param in /api/v1/notifications MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- app/soapbox/actions/notifications.ts | 23 ++++++++++++++++------- app/soapbox/utils/features.ts | 9 +++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/app/soapbox/actions/notifications.ts b/app/soapbox/actions/notifications.ts index 64311a15a..4c825ef8b 100644 --- a/app/soapbox/actions/notifications.ts +++ b/app/soapbox/actions/notifications.ts @@ -9,7 +9,7 @@ import { defineMessages } from 'react-intl'; import api, { getLinks } from 'soapbox/api'; import { getFilters, regexFromFilters } from 'soapbox/selectors'; import { isLoggedIn } from 'soapbox/utils/auth'; -import { parseVersion, PLEROMA } from 'soapbox/utils/features'; +import { getFeatures, parseVersion, PLEROMA } from 'soapbox/utils/features'; import { unescapeHTML } from 'soapbox/utils/html'; import { joinPublicPath } from 'soapbox/utils/static'; @@ -167,7 +167,7 @@ const dequeueNotifications = () => dispatch(markReadNotifications()); }; -const excludeTypesFromSettings = (getState: () => RootState) => (getSettings(getState()).getIn(['notifications', 'shows']) as ImmutableMap).filter(enabled => !enabled).keySeq().toJS(); +// 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']); @@ -180,8 +180,9 @@ const expandNotifications = ({ maxId }: Record = {}, done: () => an (dispatch: AppDispatch, getState: () => RootState) => { if (!isLoggedIn(getState)) return dispatch(noOp); - const activeFilter = getSettings(getState()).getIn(['notifications', 'quickFilter', 'active']) as string; - const notifications = getState().notifications; + const state = getState(); + const activeFilter = getSettings(state).getIn(['notifications', 'quickFilter', 'active']) as string; + const notifications = state.notifications; const isLoadingMore = !!maxId; if (notifications.get('isLoading')) { @@ -191,11 +192,19 @@ const expandNotifications = ({ maxId }: Record = {}, done: () => an const params: Record = { max_id: maxId, - exclude_types: activeFilter === 'all' - ? excludeTypesFromSettings(getState) - : excludeTypesFromFilter(activeFilter), }; + if (activeFilter !== 'all') { + const instance = state.instance; + const features = getFeatures(instance); + + if (features.notificationsIncludeTypes) { + params.types = [activeFilter]; + } else { + params.exclude_types = excludeTypesFromFilter(activeFilter); + } + } + if (!maxId && notifications.get('items').size > 0) { params.since_id = notifications.getIn(['items', 0, 'id']); } diff --git a/app/soapbox/utils/features.ts b/app/soapbox/utils/features.ts index e3683def3..b8bde6961 100644 --- a/app/soapbox/utils/features.ts +++ b/app/soapbox/utils/features.ts @@ -401,6 +401,15 @@ const getInstanceFeatures = (instance: Instance) => { v.software === PLEROMA && gte(v.version, '2.4.50'), ]), + /** + * Allows specifying notification types to include, rather than to exclude. + * @see GET /api/v1/notifications + */ + notificationsIncludeTypes: any([ + v.software === MASTODON && gte(v.compatVersion, '3.5.0'), + v.software === PLEROMA && gte(v.version, '2.4.50'), + ]), + /** * Supports pagination in threads. * @see GET /api/v1/statuses/:id/context/ancestors