mirror of
https://github.com/glitch-soc/mastodon.git
synced 2024-11-23 16:44:04 -05:00
[Glitch] Fix multiple bugs in notification requests and notification policies
Port 0a6b75b71e
to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
parent
aac6296183
commit
131696277c
@ -17,6 +17,6 @@ export const updateNotificationsPolicy = createDataLoadingThunk(
|
||||
(policy: Partial<NotificationPolicy>) => apiUpdateNotificationsPolicy(policy),
|
||||
);
|
||||
|
||||
export const decreasePendingNotificationsCount = createAction<number>(
|
||||
'notificationPolicy/decreasePendingNotificationCount',
|
||||
export const decreasePendingRequestsCount = createAction<number>(
|
||||
'notificationPolicy/decreasePendingRequestsCount',
|
||||
);
|
||||
|
@ -13,11 +13,11 @@ import type {
|
||||
ApiNotificationJSON,
|
||||
} from 'flavours/glitch/api_types/notifications';
|
||||
import type { ApiStatusJSON } from 'flavours/glitch/api_types/statuses';
|
||||
import type { AppDispatch, RootState } from 'flavours/glitch/store';
|
||||
import type { AppDispatch } from 'flavours/glitch/store';
|
||||
import { createDataLoadingThunk } from 'flavours/glitch/store/typed_functions';
|
||||
|
||||
import { importFetchedAccounts, importFetchedStatuses } from './importer';
|
||||
import { decreasePendingNotificationsCount } from './notification_policies';
|
||||
import { decreasePendingRequestsCount } from './notification_policies';
|
||||
|
||||
// TODO: refactor with notification_groups
|
||||
function dispatchAssociatedRecords(
|
||||
@ -169,19 +169,11 @@ export const expandNotificationsForRequest = createDataLoadingThunk(
|
||||
},
|
||||
);
|
||||
|
||||
const selectNotificationCountForRequest = (state: RootState, id: string) => {
|
||||
const requests = state.notificationRequests.items;
|
||||
const thisRequest = requests.find((request) => request.id === id);
|
||||
return thisRequest ? thisRequest.notifications_count : 0;
|
||||
};
|
||||
|
||||
export const acceptNotificationRequest = createDataLoadingThunk(
|
||||
'notificationRequest/accept',
|
||||
({ id }: { id: string }) => apiAcceptNotificationRequest(id),
|
||||
(_data, { dispatch, getState, discardLoadData, actionArg: { id } }) => {
|
||||
const count = selectNotificationCountForRequest(getState(), id);
|
||||
|
||||
dispatch(decreasePendingNotificationsCount(count));
|
||||
(_data, { dispatch, discardLoadData }) => {
|
||||
dispatch(decreasePendingRequestsCount(1));
|
||||
|
||||
// The payload is not used in any functions
|
||||
return discardLoadData;
|
||||
@ -191,10 +183,8 @@ export const acceptNotificationRequest = createDataLoadingThunk(
|
||||
export const dismissNotificationRequest = createDataLoadingThunk(
|
||||
'notificationRequest/dismiss',
|
||||
({ id }: { id: string }) => apiDismissNotificationRequest(id),
|
||||
(_data, { dispatch, getState, discardLoadData, actionArg: { id } }) => {
|
||||
const count = selectNotificationCountForRequest(getState(), id);
|
||||
|
||||
dispatch(decreasePendingNotificationsCount(count));
|
||||
(_data, { dispatch, discardLoadData }) => {
|
||||
dispatch(decreasePendingRequestsCount(1));
|
||||
|
||||
// The payload is not used in any functions
|
||||
return discardLoadData;
|
||||
@ -204,13 +194,8 @@ export const dismissNotificationRequest = createDataLoadingThunk(
|
||||
export const acceptNotificationRequests = createDataLoadingThunk(
|
||||
'notificationRequests/acceptBulk',
|
||||
({ ids }: { ids: string[] }) => apiAcceptNotificationRequests(ids),
|
||||
(_data, { dispatch, getState, discardLoadData, actionArg: { ids } }) => {
|
||||
const count = ids.reduce(
|
||||
(count, id) => count + selectNotificationCountForRequest(getState(), id),
|
||||
0,
|
||||
);
|
||||
|
||||
dispatch(decreasePendingNotificationsCount(count));
|
||||
(_data, { dispatch, discardLoadData, actionArg: { ids } }) => {
|
||||
dispatch(decreasePendingRequestsCount(ids.length));
|
||||
|
||||
// The payload is not used in any functions
|
||||
return discardLoadData;
|
||||
@ -220,13 +205,8 @@ export const acceptNotificationRequests = createDataLoadingThunk(
|
||||
export const dismissNotificationRequests = createDataLoadingThunk(
|
||||
'notificationRequests/dismissBulk',
|
||||
({ ids }: { ids: string[] }) => apiDismissNotificationRequests(ids),
|
||||
(_data, { dispatch, getState, discardLoadData, actionArg: { ids } }) => {
|
||||
const count = ids.reduce(
|
||||
(count, id) => count + selectNotificationCountForRequest(getState(), id),
|
||||
0,
|
||||
);
|
||||
|
||||
dispatch(decreasePendingNotificationsCount(count));
|
||||
(_data, { dispatch, discardLoadData, actionArg: { ids } }) => {
|
||||
dispatch(decreasePendingRequestsCount(ids.length));
|
||||
|
||||
// The payload is not used in any functions
|
||||
return discardLoadData;
|
||||
|
@ -91,5 +91,5 @@ export const apiAcceptNotificationRequests = async (id: string[]) => {
|
||||
};
|
||||
|
||||
export const apiDismissNotificationRequests = async (id: string[]) => {
|
||||
return apiRequestPost('v1/notifications/dismiss/dismiss', { id });
|
||||
return apiRequestPost('v1/notifications/requests/dismiss', { id });
|
||||
};
|
||||
|
@ -31,7 +31,7 @@ export const FilteredNotificationsIconButton: React.FC<{
|
||||
history.push('/notifications/requests');
|
||||
}, [history]);
|
||||
|
||||
if (policy === null || policy.summary.pending_notifications_count === 0) {
|
||||
if (policy === null || policy.summary.pending_requests_count <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ export const FilteredNotificationsBanner: React.FC = () => {
|
||||
};
|
||||
}, [dispatch]);
|
||||
|
||||
if (policy === null || policy.summary.pending_notifications_count === 0) {
|
||||
if (policy === null || policy.summary.pending_requests_count <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ import { createReducer, isAnyOf } from '@reduxjs/toolkit';
|
||||
|
||||
import {
|
||||
fetchNotificationPolicy,
|
||||
decreasePendingNotificationsCount,
|
||||
decreasePendingRequestsCount,
|
||||
updateNotificationsPolicy,
|
||||
} from 'flavours/glitch/actions/notification_policies';
|
||||
import type { NotificationPolicy } from 'flavours/glitch/models/notification_policy';
|
||||
@ -10,10 +10,9 @@ import type { NotificationPolicy } from 'flavours/glitch/models/notification_pol
|
||||
export const notificationPolicyReducer =
|
||||
createReducer<NotificationPolicy | null>(null, (builder) => {
|
||||
builder
|
||||
.addCase(decreasePendingNotificationsCount, (state, action) => {
|
||||
.addCase(decreasePendingRequestsCount, (state, action) => {
|
||||
if (state) {
|
||||
state.summary.pending_notifications_count -= action.payload;
|
||||
state.summary.pending_requests_count -= 1;
|
||||
state.summary.pending_requests_count -= action.payload;
|
||||
}
|
||||
})
|
||||
.addMatcher(
|
||||
|
Loading…
Reference in New Issue
Block a user