mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-27 23:55:52 +00:00
Switch to batch queries for accepting/dismissing all notification requests
This commit is contained in:
parent
9e0d035aaf
commit
a626a4a30c
|
@ -64,6 +64,14 @@ export const NOTIFICATION_REQUEST_DISMISS_REQUEST = 'NOTIFICATION_REQUEST_DISMIS
|
||||||
export const NOTIFICATION_REQUEST_DISMISS_SUCCESS = 'NOTIFICATION_REQUEST_DISMISS_SUCCESS';
|
export const NOTIFICATION_REQUEST_DISMISS_SUCCESS = 'NOTIFICATION_REQUEST_DISMISS_SUCCESS';
|
||||||
export const NOTIFICATION_REQUEST_DISMISS_FAIL = 'NOTIFICATION_REQUEST_DISMISS_FAIL';
|
export const NOTIFICATION_REQUEST_DISMISS_FAIL = 'NOTIFICATION_REQUEST_DISMISS_FAIL';
|
||||||
|
|
||||||
|
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';
|
||||||
|
|
||||||
export const NOTIFICATIONS_FOR_REQUEST_FETCH_REQUEST = 'NOTIFICATIONS_FOR_REQUEST_FETCH_REQUEST';
|
export const NOTIFICATIONS_FOR_REQUEST_FETCH_REQUEST = 'NOTIFICATIONS_FOR_REQUEST_FETCH_REQUEST';
|
||||||
export const NOTIFICATIONS_FOR_REQUEST_FETCH_SUCCESS = 'NOTIFICATIONS_FOR_REQUEST_FETCH_SUCCESS';
|
export const NOTIFICATIONS_FOR_REQUEST_FETCH_SUCCESS = 'NOTIFICATIONS_FOR_REQUEST_FETCH_SUCCESS';
|
||||||
export const NOTIFICATIONS_FOR_REQUEST_FETCH_FAIL = 'NOTIFICATIONS_FOR_REQUEST_FETCH_FAIL';
|
export const NOTIFICATIONS_FOR_REQUEST_FETCH_FAIL = 'NOTIFICATIONS_FOR_REQUEST_FETCH_FAIL';
|
||||||
|
@ -496,6 +504,62 @@ export const dismissNotificationRequestFail = (id, error) => ({
|
||||||
error,
|
error,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const acceptNotificationRequests = (ids) => (dispatch, getState) => {
|
||||||
|
const count = ids.reduce((count, id) => count + selectNotificationCountForRequest(getState(), id), 0);
|
||||||
|
dispatch(acceptNotificationRequestsRequest(ids));
|
||||||
|
|
||||||
|
api().post(`/api/v1/notifications/requests/accept`, { id: ids }).then(() => {
|
||||||
|
dispatch(acceptNotificationRequestsSuccess(ids));
|
||||||
|
dispatch(decreasePendingNotificationsCount(count));
|
||||||
|
}).catch(err => {
|
||||||
|
dispatch(acceptNotificationRequestFail(ids, err));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const acceptNotificationRequestsRequest = ids => ({
|
||||||
|
type: NOTIFICATION_REQUESTS_ACCEPT_REQUEST,
|
||||||
|
ids,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const acceptNotificationRequestsSuccess = ids => ({
|
||||||
|
type: NOTIFICATION_REQUESTS_ACCEPT_SUCCESS,
|
||||||
|
ids,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const acceptNotificationRequestsFail = (ids, error) => ({
|
||||||
|
type: NOTIFICATION_REQUESTS_ACCEPT_FAIL,
|
||||||
|
ids,
|
||||||
|
error,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const dismissNotificationRequests = (ids) => (dispatch, getState) => {
|
||||||
|
const count = ids.reduce((count, id) => count + selectNotificationCountForRequest(getState(), id), 0);
|
||||||
|
dispatch(acceptNotificationRequestsRequest(ids));
|
||||||
|
|
||||||
|
api().post(`/api/v1/notifications/requests/dismiss`, { id: ids }).then(() => {
|
||||||
|
dispatch(dismissNotificationRequestsSuccess(ids));
|
||||||
|
dispatch(decreasePendingNotificationsCount(count));
|
||||||
|
}).catch(err => {
|
||||||
|
dispatch(dismissNotificationRequestFail(ids, err));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const dismissNotificationRequestsRequest = ids => ({
|
||||||
|
type: NOTIFICATION_REQUESTS_DISMISS_REQUEST,
|
||||||
|
ids,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const dismissNotificationRequestsSuccess = ids => ({
|
||||||
|
type: NOTIFICATION_REQUESTS_DISMISS_SUCCESS,
|
||||||
|
ids,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const dismissNotificationRequestsFail = (ids, error) => ({
|
||||||
|
type: NOTIFICATION_REQUESTS_DISMISS_FAIL,
|
||||||
|
ids,
|
||||||
|
error,
|
||||||
|
});
|
||||||
|
|
||||||
export const fetchNotificationsForRequest = accountId => (dispatch, getState) => {
|
export const fetchNotificationsForRequest = accountId => (dispatch, getState) => {
|
||||||
const current = getState().getIn(['notificationRequests', 'current']);
|
const current = getState().getIn(['notificationRequests', 'current']);
|
||||||
const params = { account_id: accountId };
|
const params = { account_id: accountId };
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { useSelector, useDispatch } from 'react-redux';
|
||||||
import InventoryIcon from '@/material-icons/400-24px/inventory_2.svg?react';
|
import InventoryIcon from '@/material-icons/400-24px/inventory_2.svg?react';
|
||||||
import MoreHorizIcon from '@/material-icons/400-24px/more_horiz.svg?react';
|
import MoreHorizIcon from '@/material-icons/400-24px/more_horiz.svg?react';
|
||||||
import { openModal } from 'mastodon/actions/modal';
|
import { openModal } from 'mastodon/actions/modal';
|
||||||
import { fetchNotificationRequests, expandNotificationRequests, acceptNotificationRequest, dismissNotificationRequest } from 'mastodon/actions/notifications';
|
import { fetchNotificationRequests, expandNotificationRequests, acceptNotificationRequests, dismissNotificationRequests } from 'mastodon/actions/notifications';
|
||||||
import Column from 'mastodon/components/column';
|
import Column from 'mastodon/components/column';
|
||||||
import ColumnHeader from 'mastodon/components/column_header';
|
import ColumnHeader from 'mastodon/components/column_header';
|
||||||
import ScrollableList from 'mastodon/components/scrollable_list';
|
import ScrollableList from 'mastodon/components/scrollable_list';
|
||||||
|
@ -57,11 +57,8 @@ export const NotificationRequests = ({ multiColumn }) => {
|
||||||
title: intl.formatMessage(messages.confirm_accept_all_title),
|
title: intl.formatMessage(messages.confirm_accept_all_title),
|
||||||
message: intl.formatMessage(messages.confirm_accept_all_message, { count: notificationRequests.size }),
|
message: intl.formatMessage(messages.confirm_accept_all_message, { count: notificationRequests.size }),
|
||||||
confirm: intl.formatMessage(messages.confirm_accept_all_button),
|
confirm: intl.formatMessage(messages.confirm_accept_all_button),
|
||||||
onConfirm: () => {
|
onConfirm: () =>
|
||||||
notificationRequests.forEach((request) =>
|
dispatch(acceptNotificationRequests(notificationRequests.map((request) => request.get('id')))),
|
||||||
dispatch(acceptNotificationRequest(request.get('id')))
|
|
||||||
);
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
}, [dispatch, notificationRequests, intl]);
|
}, [dispatch, notificationRequests, intl]);
|
||||||
|
@ -73,11 +70,8 @@ export const NotificationRequests = ({ multiColumn }) => {
|
||||||
title: intl.formatMessage(messages.confirm_dismiss_all_title),
|
title: intl.formatMessage(messages.confirm_dismiss_all_title),
|
||||||
message: intl.formatMessage(messages.confirm_dismiss_all_message, { count: notificationRequests.size }),
|
message: intl.formatMessage(messages.confirm_dismiss_all_message, { count: notificationRequests.size }),
|
||||||
confirm: intl.formatMessage(messages.confirm_dismiss_all_button),
|
confirm: intl.formatMessage(messages.confirm_dismiss_all_button),
|
||||||
onConfirm: () => {
|
onConfirm: () =>
|
||||||
notificationRequests.forEach((request) =>
|
dispatch(dismissNotificationRequests(notificationRequests.map((request) => request.get('id')))),
|
||||||
dispatch(dismissNotificationRequest(request.get('id')))
|
|
||||||
);
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}, [dispatch, notificationRequests, intl]);
|
}, [dispatch, notificationRequests, intl]);
|
||||||
|
|
|
@ -12,6 +12,8 @@ import {
|
||||||
NOTIFICATION_REQUEST_FETCH_FAIL,
|
NOTIFICATION_REQUEST_FETCH_FAIL,
|
||||||
NOTIFICATION_REQUEST_ACCEPT_REQUEST,
|
NOTIFICATION_REQUEST_ACCEPT_REQUEST,
|
||||||
NOTIFICATION_REQUEST_DISMISS_REQUEST,
|
NOTIFICATION_REQUEST_DISMISS_REQUEST,
|
||||||
|
NOTIFICATION_REQUESTS_ACCEPT_REQUEST,
|
||||||
|
NOTIFICATION_REQUESTS_DISMISS_REQUEST,
|
||||||
NOTIFICATIONS_FOR_REQUEST_FETCH_REQUEST,
|
NOTIFICATIONS_FOR_REQUEST_FETCH_REQUEST,
|
||||||
NOTIFICATIONS_FOR_REQUEST_FETCH_SUCCESS,
|
NOTIFICATIONS_FOR_REQUEST_FETCH_SUCCESS,
|
||||||
NOTIFICATIONS_FOR_REQUEST_FETCH_FAIL,
|
NOTIFICATIONS_FOR_REQUEST_FETCH_FAIL,
|
||||||
|
@ -74,6 +76,9 @@ export const notificationRequestsReducer = (state = initialState, action) => {
|
||||||
case NOTIFICATION_REQUEST_ACCEPT_REQUEST:
|
case NOTIFICATION_REQUEST_ACCEPT_REQUEST:
|
||||||
case NOTIFICATION_REQUEST_DISMISS_REQUEST:
|
case NOTIFICATION_REQUEST_DISMISS_REQUEST:
|
||||||
return removeRequest(state, action.id);
|
return removeRequest(state, action.id);
|
||||||
|
case NOTIFICATION_REQUESTS_ACCEPT_REQUEST:
|
||||||
|
case NOTIFICATION_REQUESTS_DISMISS_REQUEST:
|
||||||
|
return action.ids.reduce((state, id) => removeRequest(state, id), state);
|
||||||
case NOTIFICATION_REQUEST_FETCH_REQUEST:
|
case NOTIFICATION_REQUEST_FETCH_REQUEST:
|
||||||
return state.set('current', initialState.get('current').set('isLoading', true));
|
return state.set('current', initialState.get('current').set('isLoading', true));
|
||||||
case NOTIFICATION_REQUEST_FETCH_SUCCESS:
|
case NOTIFICATION_REQUEST_FETCH_SUCCESS:
|
||||||
|
|
Loading…
Reference in a new issue