2024-06-18 09:23:30 -04:00
|
|
|
import { createReducer, isAnyOf } from '@reduxjs/toolkit';
|
|
|
|
|
|
|
|
import {
|
|
|
|
fetchNotificationPolicy,
|
2024-07-26 05:36:54 -04:00
|
|
|
decreasePendingNotificationsCount,
|
2024-06-18 09:23:30 -04:00
|
|
|
updateNotificationsPolicy,
|
|
|
|
} from 'mastodon/actions/notification_policies';
|
|
|
|
import type { NotificationPolicy } from 'mastodon/models/notification_policy';
|
|
|
|
|
|
|
|
export const notificationPolicyReducer =
|
|
|
|
createReducer<NotificationPolicy | null>(null, (builder) => {
|
2024-07-26 05:36:54 -04:00
|
|
|
builder
|
|
|
|
.addCase(decreasePendingNotificationsCount, (state, action) => {
|
|
|
|
if (state) {
|
|
|
|
state.summary.pending_notifications_count -= action.payload;
|
|
|
|
state.summary.pending_requests_count -= 1;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.addMatcher(
|
|
|
|
isAnyOf(
|
|
|
|
fetchNotificationPolicy.fulfilled,
|
|
|
|
updateNotificationsPolicy.fulfilled,
|
|
|
|
),
|
|
|
|
(_state, action) => action.payload,
|
|
|
|
);
|
2024-06-18 09:23:30 -04:00
|
|
|
});
|