mirror of
https://github.com/mastodon/mastodon.git
synced 2025-01-09 03:04:19 +01:00
Further cleanup unused notification actions/reducers
This commit is contained in:
parent
7efb3eb134
commit
5ab7f02195
3 changed files with 2 additions and 76 deletions
|
@ -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,
|
||||
|
|
|
@ -9,7 +9,6 @@ export const notificationsUpdate = createAction(
|
|||
...args
|
||||
}: {
|
||||
notification: ApiNotificationJSON;
|
||||
usePendingItems: boolean;
|
||||
playSound: boolean;
|
||||
}) => ({
|
||||
payload: args,
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue