From 11de3dbef6fc719bd12379649a888ae84ad9b347 Mon Sep 17 00:00:00 2001 From: Claire Date: Mon, 16 Sep 2024 15:12:10 +0200 Subject: [PATCH] [Glitch] Enable grouped notifications unconditionally Port c620452fd7e0e3b083bae4b68fa09384df322f4a to glitch-soc Signed-off-by: Claire --- .../flavours/glitch/actions/markers.ts | 8 +----- .../actions/notifications_migration.tsx | 8 ++---- .../flavours/glitch/actions/streaming.js | 28 ++++++------------- .../components/column_settings.jsx | 14 ---------- .../glitch/features/notifications_wrapper.jsx | 7 +---- .../ui/components/navigation_panel.jsx | 11 +++----- .../flavours/glitch/initial_state.js | 2 -- .../flavours/glitch/selectors/settings.ts | 5 ---- 8 files changed, 16 insertions(+), 67 deletions(-) diff --git a/app/javascript/flavours/glitch/actions/markers.ts b/app/javascript/flavours/glitch/actions/markers.ts index 666756bcd1..37067dbcf7 100644 --- a/app/javascript/flavours/glitch/actions/markers.ts +++ b/app/javascript/flavours/glitch/actions/markers.ts @@ -2,7 +2,6 @@ import { debounce } from 'lodash'; import type { MarkerJSON } from 'flavours/glitch/api_types/markers'; import { getAccessToken } from 'flavours/glitch/initial_state'; -import { selectUseGroupedNotifications } from 'flavours/glitch/selectors/settings'; import type { AppDispatch, RootState } from 'flavours/glitch/store'; import { createAppAsyncThunk } from 'flavours/glitch/store/typed_functions'; @@ -76,12 +75,7 @@ interface MarkerParam { } function getLastNotificationId(state: RootState): string | undefined { - // eslint-disable-next-line @typescript-eslint/no-unsafe-return - return selectUseGroupedNotifications(state) - ? state.notificationGroups.lastReadId - : // @ts-expect-error state.notifications is not yet typed - // eslint-disable-next-line @typescript-eslint/no-unsafe-call - state.getIn(['notifications', 'lastReadId']); + return state.notificationGroups.lastReadId; } const buildPostMarkersParams = (state: RootState) => { diff --git a/app/javascript/flavours/glitch/actions/notifications_migration.tsx b/app/javascript/flavours/glitch/actions/notifications_migration.tsx index 6789dbf38c..6f2d38b9e9 100644 --- a/app/javascript/flavours/glitch/actions/notifications_migration.tsx +++ b/app/javascript/flavours/glitch/actions/notifications_migration.tsx @@ -1,14 +1,10 @@ -import { selectUseGroupedNotifications } from 'flavours/glitch/selectors/settings'; import { createAppAsyncThunk } from 'flavours/glitch/store'; import { fetchNotifications } from './notification_groups'; -import { expandNotifications } from './notifications'; export const initializeNotifications = createAppAsyncThunk( 'notifications/initialize', - (_, { dispatch, getState }) => { - if (selectUseGroupedNotifications(getState())) - void dispatch(fetchNotifications()); - else void dispatch(expandNotifications({})); + (_, { dispatch }) => { + void dispatch(fetchNotifications()); }, ); diff --git a/app/javascript/flavours/glitch/actions/streaming.js b/app/javascript/flavours/glitch/actions/streaming.js index e6eb7b2fad..7948984fba 100644 --- a/app/javascript/flavours/glitch/actions/streaming.js +++ b/app/javascript/flavours/glitch/actions/streaming.js @@ -1,7 +1,5 @@ // @ts-check -import { selectUseGroupedNotifications } from 'flavours/glitch/selectors/settings'; - import { getLocale } from '../locales'; import { connectStream } from '../stream'; @@ -105,18 +103,14 @@ export const connectTimelineStream = (timelineId, channelName, params = {}, opti const notificationJSON = JSON.parse(data.payload); dispatch(updateNotifications(notificationJSON, messages, locale)); // TODO: remove this once the groups feature replaces the previous one - if(selectUseGroupedNotifications(getState())) { - dispatch(processNewNotificationForGroups(notificationJSON)); - } + dispatch(processNewNotificationForGroups(notificationJSON)); break; } case 'notifications_merged': const state = getState(); if (state.notifications.top || !state.notifications.mounted) dispatch(expandNotifications({ forceLoad: true, maxId: undefined })); - if (selectUseGroupedNotifications(state)) { - dispatch(refreshStaleNotificationGroups()); - } + dispatch(refreshStaleNotificationGroups()); break; case 'conversation': // @ts-expect-error @@ -141,21 +135,15 @@ export const connectTimelineStream = (timelineId, channelName, params = {}, opti /** * @param {Function} dispatch - * @param {Function} getState */ -async function refreshHomeTimelineAndNotification(dispatch, getState) { +async function refreshHomeTimelineAndNotification(dispatch) { await dispatch(expandHomeTimeline({ maxId: undefined })); - // TODO: remove this once the groups feature replaces the previous one - if(selectUseGroupedNotifications(getState())) { - // TODO: polling for merged notifications - try { - await dispatch(pollRecentGroupNotifications()); - } catch { - // TODO - } - } else { - await dispatch(expandNotifications({})); + // TODO: polling for merged notifications + try { + await dispatch(pollRecentGroupNotifications()); + } catch { + // TODO } await dispatch(fetchAnnouncements()); diff --git a/app/javascript/flavours/glitch/features/notifications/components/column_settings.jsx b/app/javascript/flavours/glitch/features/notifications/components/column_settings.jsx index 3bd040eb51..ea57f2999b 100644 --- a/app/javascript/flavours/glitch/features/notifications/components/column_settings.jsx +++ b/app/javascript/flavours/glitch/features/notifications/components/column_settings.jsx @@ -6,7 +6,6 @@ import { FormattedMessage } from 'react-intl'; import ImmutablePropTypes from 'react-immutable-proptypes'; import { identityContextPropShape, withIdentity } from 'flavours/glitch/identity_context'; -import { forceGroupedNotifications } from 'flavours/glitch/initial_state'; import { PERMISSION_MANAGE_USERS, PERMISSION_MANAGE_REPORTS } from 'flavours/glitch/permissions'; import ClearColumnButton from './clear_column_button'; @@ -36,7 +35,6 @@ class ColumnSettings extends PureComponent { const { settings, pushSettings, onChange, onClear, alertsEnabled, browserSupport, browserPermission, onRequestNotificationPermission } = this.props; const unreadMarkersShowStr = ; - const groupingShowStr = ; const filterBarShowStr = ; const filterAdvancedStr = ; const alertStr = ; @@ -79,18 +77,6 @@ class ColumnSettings extends PureComponent { - {!forceGroupedNotifications && ( -
-

- -

- -
- -
-
- )} -

diff --git a/app/javascript/flavours/glitch/features/notifications_wrapper.jsx b/app/javascript/flavours/glitch/features/notifications_wrapper.jsx index ab3eff889c..e19aa9d07d 100644 --- a/app/javascript/flavours/glitch/features/notifications_wrapper.jsx +++ b/app/javascript/flavours/glitch/features/notifications_wrapper.jsx @@ -1,13 +1,8 @@ -import Notifications from 'flavours/glitch/features/notifications'; import Notifications_v2 from 'flavours/glitch/features/notifications_v2'; -import { selectUseGroupedNotifications } from 'flavours/glitch/selectors/settings'; -import { useAppSelector } from 'flavours/glitch/store'; export const NotificationsWrapper = (props) => { - const optedInGroupedNotifications = useAppSelector(selectUseGroupedNotifications); - return ( - optedInGroupedNotifications ? : + ); }; diff --git a/app/javascript/flavours/glitch/features/ui/components/navigation_panel.jsx b/app/javascript/flavours/glitch/features/ui/components/navigation_panel.jsx index 905387caea..3e3fa5d9f1 100644 --- a/app/javascript/flavours/glitch/features/ui/components/navigation_panel.jsx +++ b/app/javascript/flavours/glitch/features/ui/components/navigation_panel.jsx @@ -36,7 +36,6 @@ import { timelinePreview, trendsEnabled } from 'flavours/glitch/initial_state'; import { transientSingleColumn } from 'flavours/glitch/is_mobile'; import { canManageReports, canViewAdminDashboard } from 'flavours/glitch/permissions'; import { selectUnreadNotificationGroupsCount } from 'flavours/glitch/selectors/notifications'; -import { selectUseGroupedNotifications } from 'flavours/glitch/selectors/settings'; import { preferencesLink } from 'flavours/glitch/utils/backend_links'; import ColumnLink from './column_link'; @@ -66,19 +65,17 @@ const messages = defineMessages({ }); const NotificationsLink = () => { - const optedInGroupedNotifications = useSelector(selectUseGroupedNotifications); - const count = useSelector(state => state.getIn(['local_settings', 'notifications', 'tab_badge']) ? state.getIn(['notifications', 'unread']) : 0); + const count = useSelector(selectUnreadNotificationGroupsCount); + const showCount = useSelector(state => state.getIn(['local_settings', 'notifications', 'tab_badge'])); const intl = useIntl(); - const newCount = useSelector(selectUnreadNotificationGroupsCount); - return ( } - activeIcon={} + icon={} + activeIcon={} text={intl.formatMessage(messages.notifications)} /> ); diff --git a/app/javascript/flavours/glitch/initial_state.js b/app/javascript/flavours/glitch/initial_state.js index ee8e901a4f..fd31b54e79 100644 --- a/app/javascript/flavours/glitch/initial_state.js +++ b/app/javascript/flavours/glitch/initial_state.js @@ -46,7 +46,6 @@ * @property {boolean=} use_pending_items * @property {string} version * @property {string} sso_redirect - * @property {boolean} force_grouped_notifications * @property {string} status_page_url * @property {boolean} system_emoji_font * @property {string} default_content_type @@ -138,7 +137,6 @@ export const languages = initialState?.languages; export const criticalUpdatesPending = initialState?.critical_updates_pending; export const statusPageUrl = getMeta('status_page_url'); export const sso_redirect = getMeta('sso_redirect'); -export const forceGroupedNotifications = getMeta('force_grouped_notifications'); // Glitch-soc-specific settings export const maxFeedHashtags = (initialState && initialState.max_feed_hashtags) || 4; diff --git a/app/javascript/flavours/glitch/selectors/settings.ts b/app/javascript/flavours/glitch/selectors/settings.ts index c9cfd6dde5..9a1a2c990b 100644 --- a/app/javascript/flavours/glitch/selectors/settings.ts +++ b/app/javascript/flavours/glitch/selectors/settings.ts @@ -1,4 +1,3 @@ -import { forceGroupedNotifications } from 'flavours/glitch/initial_state'; import type { RootState } from 'flavours/glitch/store'; /* eslint-disable @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access */ @@ -26,10 +25,6 @@ export const selectSettingsNotificationsQuickFilterAdvanced = ( ) => state.settings.getIn(['notifications', 'quickFilter', 'advanced']) as boolean; -export const selectUseGroupedNotifications = (state: RootState) => - forceGroupedNotifications || - (state.settings.getIn(['notifications', 'groupingBeta']) as boolean); - export const selectSettingsNotificationsShowUnread = (state: RootState) => state.settings.getIn(['notifications', 'showUnread']) as boolean;