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