[Glitch] Enable grouped notifications unconditionally

Port c620452fd7 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
Claire 2024-09-16 15:12:10 +02:00
parent 6de18bb475
commit 11de3dbef6
8 changed files with 16 additions and 67 deletions

View file

@ -2,7 +2,6 @@ import { debounce } from 'lodash';
import type { MarkerJSON } from 'flavours/glitch/api_types/markers'; import type { MarkerJSON } from 'flavours/glitch/api_types/markers';
import { getAccessToken } from 'flavours/glitch/initial_state'; import { getAccessToken } from 'flavours/glitch/initial_state';
import { selectUseGroupedNotifications } from 'flavours/glitch/selectors/settings';
import type { AppDispatch, RootState } from 'flavours/glitch/store'; import type { AppDispatch, RootState } from 'flavours/glitch/store';
import { createAppAsyncThunk } from 'flavours/glitch/store/typed_functions'; import { createAppAsyncThunk } from 'flavours/glitch/store/typed_functions';
@ -76,12 +75,7 @@ interface MarkerParam {
} }
function getLastNotificationId(state: RootState): string | undefined { function getLastNotificationId(state: RootState): string | undefined {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return return state.notificationGroups.lastReadId;
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']);
} }
const buildPostMarkersParams = (state: RootState) => { const buildPostMarkersParams = (state: RootState) => {

View file

@ -1,14 +1,10 @@
import { selectUseGroupedNotifications } from 'flavours/glitch/selectors/settings';
import { createAppAsyncThunk } from 'flavours/glitch/store'; import { createAppAsyncThunk } from 'flavours/glitch/store';
import { fetchNotifications } from './notification_groups'; import { fetchNotifications } from './notification_groups';
import { expandNotifications } from './notifications';
export const initializeNotifications = createAppAsyncThunk( export const initializeNotifications = createAppAsyncThunk(
'notifications/initialize', 'notifications/initialize',
(_, { dispatch, getState }) => { (_, { dispatch }) => {
if (selectUseGroupedNotifications(getState())) void dispatch(fetchNotifications());
void dispatch(fetchNotifications());
else void dispatch(expandNotifications({}));
}, },
); );

View file

@ -1,7 +1,5 @@
// @ts-check // @ts-check
import { selectUseGroupedNotifications } from 'flavours/glitch/selectors/settings';
import { getLocale } from '../locales'; import { getLocale } from '../locales';
import { connectStream } from '../stream'; import { connectStream } from '../stream';
@ -105,18 +103,14 @@ export const connectTimelineStream = (timelineId, channelName, params = {}, opti
const notificationJSON = JSON.parse(data.payload); const notificationJSON = JSON.parse(data.payload);
dispatch(updateNotifications(notificationJSON, messages, locale)); dispatch(updateNotifications(notificationJSON, messages, locale));
// TODO: remove this once the groups feature replaces the previous one // TODO: remove this once the groups feature replaces the previous one
if(selectUseGroupedNotifications(getState())) { dispatch(processNewNotificationForGroups(notificationJSON));
dispatch(processNewNotificationForGroups(notificationJSON));
}
break; break;
} }
case 'notifications_merged': case 'notifications_merged':
const state = getState(); const state = getState();
if (state.notifications.top || !state.notifications.mounted) if (state.notifications.top || !state.notifications.mounted)
dispatch(expandNotifications({ forceLoad: true, maxId: undefined })); dispatch(expandNotifications({ forceLoad: true, maxId: undefined }));
if (selectUseGroupedNotifications(state)) { dispatch(refreshStaleNotificationGroups());
dispatch(refreshStaleNotificationGroups());
}
break; break;
case 'conversation': case 'conversation':
// @ts-expect-error // @ts-expect-error
@ -141,21 +135,15 @@ export const connectTimelineStream = (timelineId, channelName, params = {}, opti
/** /**
* @param {Function} dispatch * @param {Function} dispatch
* @param {Function} getState
*/ */
async function refreshHomeTimelineAndNotification(dispatch, getState) { async function refreshHomeTimelineAndNotification(dispatch) {
await dispatch(expandHomeTimeline({ maxId: undefined })); await dispatch(expandHomeTimeline({ maxId: undefined }));
// TODO: remove this once the groups feature replaces the previous one // TODO: polling for merged notifications
if(selectUseGroupedNotifications(getState())) { try {
// TODO: polling for merged notifications await dispatch(pollRecentGroupNotifications());
try { } catch {
await dispatch(pollRecentGroupNotifications()); // TODO
} catch {
// TODO
}
} else {
await dispatch(expandNotifications({}));
} }
await dispatch(fetchAnnouncements()); await dispatch(fetchAnnouncements());

View file

@ -6,7 +6,6 @@ import { FormattedMessage } from 'react-intl';
import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePropTypes from 'react-immutable-proptypes';
import { identityContextPropShape, withIdentity } from 'flavours/glitch/identity_context'; 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 { PERMISSION_MANAGE_USERS, PERMISSION_MANAGE_REPORTS } from 'flavours/glitch/permissions';
import ClearColumnButton from './clear_column_button'; 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 { settings, pushSettings, onChange, onClear, alertsEnabled, browserSupport, browserPermission, onRequestNotificationPermission } = this.props;
const unreadMarkersShowStr = <FormattedMessage id='notifications.column_settings.unread_notifications.highlight' defaultMessage='Highlight unread notifications' />; const unreadMarkersShowStr = <FormattedMessage id='notifications.column_settings.unread_notifications.highlight' defaultMessage='Highlight unread notifications' />;
const groupingShowStr = <FormattedMessage id='notifications.column_settings.beta.grouping' defaultMessage='Group notifications' />;
const filterBarShowStr = <FormattedMessage id='notifications.column_settings.filter_bar.show_bar' defaultMessage='Show filter bar' />; const filterBarShowStr = <FormattedMessage id='notifications.column_settings.filter_bar.show_bar' defaultMessage='Show filter bar' />;
const filterAdvancedStr = <FormattedMessage id='notifications.column_settings.filter_bar.advanced' defaultMessage='Display all categories' />; const filterAdvancedStr = <FormattedMessage id='notifications.column_settings.filter_bar.advanced' defaultMessage='Display all categories' />;
const alertStr = <FormattedMessage id='notifications.column_settings.alert' defaultMessage='Desktop notifications' />; const alertStr = <FormattedMessage id='notifications.column_settings.alert' defaultMessage='Desktop notifications' />;
@ -79,18 +77,6 @@ class ColumnSettings extends PureComponent {
</div> </div>
</section> </section>
{!forceGroupedNotifications && (
<section role='group' aria-labelledby='notifications-beta'>
<h3 id='notifications-beta'>
<FormattedMessage id='notifications.column_settings.beta.category' defaultMessage='Experimental features' />
</h3>
<div className='column-settings__row'>
<SettingToggle id='unread-notification-markers' prefix='notifications' settings={settings} settingPath={['groupingBeta']} onChange={onChange} label={groupingShowStr} />
</div>
</section>
)}
<section role='group' aria-labelledby='notifications-unread-markers'> <section role='group' aria-labelledby='notifications-unread-markers'>
<h3 id='notifications-unread-markers'> <h3 id='notifications-unread-markers'>
<FormattedMessage id='notifications.column_settings.unread_notifications.category' defaultMessage='Unread notifications' /> <FormattedMessage id='notifications.column_settings.unread_notifications.category' defaultMessage='Unread notifications' />

View file

@ -1,13 +1,8 @@
import Notifications from 'flavours/glitch/features/notifications';
import Notifications_v2 from 'flavours/glitch/features/notifications_v2'; 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) => { export const NotificationsWrapper = (props) => {
const optedInGroupedNotifications = useAppSelector(selectUseGroupedNotifications);
return ( return (
optedInGroupedNotifications ? <Notifications_v2 {...props} /> : <Notifications {...props} /> <Notifications_v2 {...props} />
); );
}; };

View file

@ -36,7 +36,6 @@ import { timelinePreview, trendsEnabled } from 'flavours/glitch/initial_state';
import { transientSingleColumn } from 'flavours/glitch/is_mobile'; import { transientSingleColumn } from 'flavours/glitch/is_mobile';
import { canManageReports, canViewAdminDashboard } from 'flavours/glitch/permissions'; import { canManageReports, canViewAdminDashboard } from 'flavours/glitch/permissions';
import { selectUnreadNotificationGroupsCount } from 'flavours/glitch/selectors/notifications'; import { selectUnreadNotificationGroupsCount } from 'flavours/glitch/selectors/notifications';
import { selectUseGroupedNotifications } from 'flavours/glitch/selectors/settings';
import { preferencesLink } from 'flavours/glitch/utils/backend_links'; import { preferencesLink } from 'flavours/glitch/utils/backend_links';
import ColumnLink from './column_link'; import ColumnLink from './column_link';
@ -66,19 +65,17 @@ const messages = defineMessages({
}); });
const NotificationsLink = () => { const NotificationsLink = () => {
const optedInGroupedNotifications = useSelector(selectUseGroupedNotifications); const count = useSelector(selectUnreadNotificationGroupsCount);
const count = useSelector(state => state.getIn(['local_settings', 'notifications', 'tab_badge']) ? state.getIn(['notifications', 'unread']) : 0); const showCount = useSelector(state => state.getIn(['local_settings', 'notifications', 'tab_badge']));
const intl = useIntl(); const intl = useIntl();
const newCount = useSelector(selectUnreadNotificationGroupsCount);
return ( return (
<ColumnLink <ColumnLink
key='notifications' key='notifications'
transparent transparent
to='/notifications' to='/notifications'
icon={<IconWithBadge id='bell' icon={NotificationsIcon} count={optedInGroupedNotifications ? newCount : count} className='column-link__icon' />} icon={<IconWithBadge id='bell' icon={NotificationsIcon} count={showCount ? count : 0} className='column-link__icon' />}
activeIcon={<IconWithBadge id='bell' icon={NotificationsActiveIcon} count={optedInGroupedNotifications ? newCount : count} className='column-link__icon' />} activeIcon={<IconWithBadge id='bell' icon={NotificationsActiveIcon} count={showCount ? count : 0} className='column-link__icon' />}
text={intl.formatMessage(messages.notifications)} text={intl.formatMessage(messages.notifications)}
/> />
); );

View file

@ -46,7 +46,6 @@
* @property {boolean=} use_pending_items * @property {boolean=} use_pending_items
* @property {string} version * @property {string} version
* @property {string} sso_redirect * @property {string} sso_redirect
* @property {boolean} force_grouped_notifications
* @property {string} status_page_url * @property {string} status_page_url
* @property {boolean} system_emoji_font * @property {boolean} system_emoji_font
* @property {string} default_content_type * @property {string} default_content_type
@ -138,7 +137,6 @@ export const languages = initialState?.languages;
export const criticalUpdatesPending = initialState?.critical_updates_pending; export const criticalUpdatesPending = initialState?.critical_updates_pending;
export const statusPageUrl = getMeta('status_page_url'); export const statusPageUrl = getMeta('status_page_url');
export const sso_redirect = getMeta('sso_redirect'); export const sso_redirect = getMeta('sso_redirect');
export const forceGroupedNotifications = getMeta('force_grouped_notifications');
// Glitch-soc-specific settings // Glitch-soc-specific settings
export const maxFeedHashtags = (initialState && initialState.max_feed_hashtags) || 4; export const maxFeedHashtags = (initialState && initialState.max_feed_hashtags) || 4;

View file

@ -1,4 +1,3 @@
import { forceGroupedNotifications } from 'flavours/glitch/initial_state';
import type { RootState } from 'flavours/glitch/store'; import type { RootState } from 'flavours/glitch/store';
/* eslint-disable @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access */ /* 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; 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) => export const selectSettingsNotificationsShowUnread = (state: RootState) =>
state.settings.getIn(['notifications', 'showUnread']) as boolean; state.settings.getIn(['notifications', 'showUnread']) as boolean;