From 5ab7f02195232f7e9950f139cdf133db7ea2c157 Mon Sep 17 00:00:00 2001 From: Claire Date: Fri, 3 Jan 2025 11:41:46 +0100 Subject: [PATCH] Further cleanup unused notification actions/reducers --- .../mastodon/actions/notifications.js | 9 +-- .../mastodon/actions/notifications_typed.ts | 1 - .../mastodon/reducers/notifications.js | 68 +------------------ 3 files changed, 2 insertions(+), 76 deletions(-) diff --git a/app/javascript/mastodon/actions/notifications.js b/app/javascript/mastodon/actions/notifications.js index ed718289f0..3266df5a59 100644 --- a/app/javascript/mastodon/actions/notifications.js +++ b/app/javascript/mastodon/actions/notifications.js @@ -1,8 +1,6 @@ import { IntlMessageFormat } from 'intl-messageformat'; import { defineMessages } from 'react-intl'; -import { usePendingItems as preferPendingItems } from 'mastodon/initial_state'; - import { unescapeHTML } from '../utils/html'; import { requestNotificationPermission } from '../utils/notifications'; @@ -25,10 +23,6 @@ export const NOTIFICATIONS_FILTER_SET = 'NOTIFICATIONS_FILTER_SET'; export const NOTIFICATIONS_SET_BROWSER_SUPPORT = 'NOTIFICATIONS_SET_BROWSER_SUPPORT'; export const NOTIFICATIONS_SET_BROWSER_PERMISSION = 'NOTIFICATIONS_SET_BROWSER_PERMISSION'; -export const NOTIFICATION_REQUESTS_ACCEPT_REQUEST = 'NOTIFICATION_REQUESTS_ACCEPT_REQUEST'; -export const NOTIFICATION_REQUESTS_ACCEPT_SUCCESS = 'NOTIFICATION_REQUESTS_ACCEPT_SUCCESS'; -export const NOTIFICATION_REQUESTS_ACCEPT_FAIL = 'NOTIFICATION_REQUESTS_ACCEPT_FAIL'; - export const NOTIFICATION_REQUESTS_DISMISS_REQUEST = 'NOTIFICATION_REQUESTS_DISMISS_REQUEST'; export const NOTIFICATION_REQUESTS_DISMISS_SUCCESS = 'NOTIFICATION_REQUESTS_DISMISS_SUCCESS'; export const NOTIFICATION_REQUESTS_DISMISS_FAIL = 'NOTIFICATION_REQUESTS_DISMISS_FAIL'; @@ -74,8 +68,7 @@ export function updateNotifications(notification, intlMessages, intlLocale) { dispatch(importFetchedAccount(notification.report.target_account)); } - - dispatch(notificationsUpdate({ notification, preferPendingItems, playSound: playSound && !filtered})); + dispatch(notificationsUpdate({ notification, playSound: playSound && !filtered})); } else if (playSound && !filtered) { dispatch({ type: NOTIFICATIONS_UPDATE_NOOP, diff --git a/app/javascript/mastodon/actions/notifications_typed.ts b/app/javascript/mastodon/actions/notifications_typed.ts index 88d942d45e..3eb1230666 100644 --- a/app/javascript/mastodon/actions/notifications_typed.ts +++ b/app/javascript/mastodon/actions/notifications_typed.ts @@ -9,7 +9,6 @@ export const notificationsUpdate = createAction( ...args }: { notification: ApiNotificationJSON; - usePendingItems: boolean; playSound: boolean; }) => ({ payload: args, diff --git a/app/javascript/mastodon/reducers/notifications.js b/app/javascript/mastodon/reducers/notifications.js index c426662e5d..b47e24e397 100644 --- a/app/javascript/mastodon/reducers/notifications.js +++ b/app/javascript/mastodon/reducers/notifications.js @@ -1,27 +1,11 @@ -import { fromJS, Map as ImmutableMap, List as ImmutableList } from 'immutable'; - -import { blockDomainSuccess } from 'mastodon/actions/domain_blocks'; -import { timelineDelete } from 'mastodon/actions/timelines_typed'; +import { fromJS, Map as ImmutableMap } from 'immutable'; import { - authorizeFollowRequestSuccess, - blockAccountSuccess, - muteAccountSuccess, - rejectFollowRequestSuccess, -} from '../actions/accounts'; -import { clearNotifications } from '../actions/notification_groups'; -import { - notificationsUpdate, - NOTIFICATIONS_FILTER_SET, NOTIFICATIONS_SET_BROWSER_SUPPORT, NOTIFICATIONS_SET_BROWSER_PERMISSION, } from '../actions/notifications'; -import { disconnectTimeline } from '../actions/timelines'; const initialState = ImmutableMap({ - pendingItems: ImmutableList(), - items: ImmutableList(), - isLoading: 0, browserSupport: false, browserPermission: 'default', }); @@ -37,58 +21,8 @@ export const notificationToMap = notification => ImmutableMap({ moderation_warning: notification.moderation_warning ? fromJS(notification.moderation_warning) : null, }); -const normalizeNotification = (state, notification, usePendingItems) => { - // Under currently unknown conditions, the client may receive duplicates from the server - if (state.get('pendingItems').some((item) => item?.get('id') === notification.id) || state.get('items').some((item) => item?.get('id') === notification.id)) { - return state; - } - - if (usePendingItems || !state.get('pendingItems').isEmpty()) { - return state.update('pendingItems', list => list.unshift(notificationToMap(notification))); - } - - return state.update('items', list => { - if (list.size > 40) { - list = list.take(20); - } - - return list.unshift(notificationToMap(notification)); - }); -}; - -const filterNotifications = (state, accountIds, type) => { - const helper = list => list.filterNot(item => item !== null && accountIds.includes(item.get('account')) && (type === undefined || type === item.get('type'))); - return state.update('items', helper).update('pendingItems', helper); -}; - -const deleteByStatus = (state, statusId) => { - const helper = list => list.filterNot(item => item !== null && item.get('status') === statusId); - return state.update('items', helper).update('pendingItems', helper); -}; - export default function notifications(state = initialState, action) { switch(action.type) { - case NOTIFICATIONS_FILTER_SET: - return state.set('items', ImmutableList()).set('pendingItems', ImmutableList()); - case notificationsUpdate.type: - return normalizeNotification(state, action.payload.notification, action.payload.usePendingItems); - case blockAccountSuccess.type: - return filterNotifications(state, [action.payload.relationship.id]); - case muteAccountSuccess.type: - return action.payload.relationship.muting_notifications ? filterNotifications(state, [action.payload.relationship.id]) : state; - case blockDomainSuccess.type: - return filterNotifications(state, action.payload.accounts); - case authorizeFollowRequestSuccess.type: - case rejectFollowRequestSuccess.type: - return filterNotifications(state, [action.payload.id], 'follow_request'); - case clearNotifications.pending.type: - return state.set('items', ImmutableList()).set('pendingItems', ImmutableList()); - case timelineDelete.type: - return deleteByStatus(state, action.payload.statusId); - case disconnectTimeline.type: - return action.payload.timeline === 'home' ? - state.update(action.payload.usePendingItems ? 'pendingItems' : 'items', items => items.first() ? items.unshift(null) : items) : - state; case NOTIFICATIONS_SET_BROWSER_SUPPORT: return state.set('browserSupport', action.value); case NOTIFICATIONS_SET_BROWSER_PERMISSION: