Merge remote-tracking branch 'parent/main' into upstream-20240813

This commit is contained in:
KMY 2024-08-13 07:01:38 +09:00
commit e7ccc0539f
358 changed files with 4653 additions and 4261 deletions

View file

@ -48,6 +48,7 @@ interface NotificationGroupsState {
scrolledToTop: boolean;
isLoading: boolean;
lastReadId: string;
readMarkerId: string;
mounted: number;
isTabVisible: boolean;
}
@ -58,7 +59,8 @@ const initialState: NotificationGroupsState = {
scrolledToTop: false,
isLoading: false,
// The following properties are used to track unread notifications
lastReadId: '0', // used for unread notifications
lastReadId: '0', // used internally for unread notifications
readMarkerId: '0', // user-facing and updated when focus changes
mounted: 0, // number of mounted notification list components, usually 0 or 1
isTabVisible: true,
};
@ -284,6 +286,12 @@ function updateLastReadId(
}
}
function commitLastReadId(state: NotificationGroupsState) {
if (shouldMarkNewNotificationsAsRead(state)) {
state.readMarkerId = state.lastReadId;
}
}
export const notificationGroupsReducer = createReducer<NotificationGroupsState>(
initialState,
(builder) => {
@ -379,12 +387,14 @@ export const notificationGroupsReducer = createReducer<NotificationGroupsState>(
})
.addCase(processNewNotificationForGroups.fulfilled, (state, action) => {
const notification = action.payload;
processNewNotification(
usePendingItems ? state.pendingGroups : state.groups,
notification,
);
updateLastReadId(state);
trimNotifications(state);
if (notification) {
processNewNotification(
usePendingItems ? state.pendingGroups : state.groups,
notification,
);
updateLastReadId(state);
trimNotifications(state);
}
})
.addCase(disconnectTimeline, (state, action) => {
if (action.payload.timeline === 'home') {
@ -457,6 +467,7 @@ export const notificationGroupsReducer = createReducer<NotificationGroupsState>(
compareId(state.lastReadId, mostRecentGroup.page_max_id) < 0
)
state.lastReadId = mostRecentGroup.page_max_id;
commitLastReadId(state);
})
.addCase(fetchMarkers.fulfilled, (state, action) => {
if (
@ -465,11 +476,15 @@ export const notificationGroupsReducer = createReducer<NotificationGroupsState>(
state.lastReadId,
action.payload.markers.notifications.last_read_id,
) < 0
)
) {
state.lastReadId = action.payload.markers.notifications.last_read_id;
state.readMarkerId =
action.payload.markers.notifications.last_read_id;
}
})
.addCase(mountNotifications, (state) => {
state.mounted += 1;
commitLastReadId(state);
updateLastReadId(state);
})
.addCase(unmountNotifications, (state) => {
@ -477,6 +492,7 @@ export const notificationGroupsReducer = createReducer<NotificationGroupsState>(
})
.addCase(focusApp, (state) => {
state.isTabVisible = true;
commitLastReadId(state);
updateLastReadId(state);
})
.addCase(unfocusApp, (state) => {

View file

@ -1,5 +1,6 @@
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
import { blockAccountSuccess, muteAccountSuccess } from 'mastodon/actions/accounts';
import {
NOTIFICATION_REQUESTS_EXPAND_REQUEST,
NOTIFICATION_REQUESTS_EXPAND_SUCCESS,
@ -12,6 +13,8 @@ import {
NOTIFICATION_REQUEST_FETCH_FAIL,
NOTIFICATION_REQUEST_ACCEPT_REQUEST,
NOTIFICATION_REQUEST_DISMISS_REQUEST,
NOTIFICATION_REQUESTS_ACCEPT_REQUEST,
NOTIFICATION_REQUESTS_DISMISS_REQUEST,
NOTIFICATIONS_FOR_REQUEST_FETCH_REQUEST,
NOTIFICATIONS_FOR_REQUEST_FETCH_SUCCESS,
NOTIFICATIONS_FOR_REQUEST_FETCH_FAIL,
@ -51,6 +54,14 @@ const removeRequest = (state, id) => {
return state.update('items', list => list.filterNot(item => item.get('id') === id));
};
const removeRequestByAccount = (state, account_id) => {
if (state.getIn(['current', 'item', 'account']) === account_id) {
state = state.setIn(['current', 'removed'], true);
}
return state.update('items', list => list.filterNot(item => item.get('account') === account_id));
};
export const notificationRequestsReducer = (state = initialState, action) => {
switch(action.type) {
case NOTIFICATION_REQUESTS_FETCH_SUCCESS:
@ -74,6 +85,13 @@ export const notificationRequestsReducer = (state = initialState, action) => {
case NOTIFICATION_REQUEST_ACCEPT_REQUEST:
case NOTIFICATION_REQUEST_DISMISS_REQUEST:
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 blockAccountSuccess.type:
return removeRequestByAccount(state, action.payload.relationship.id);
case muteAccountSuccess.type:
return action.payload.relationship.muting_notifications ? removeRequestByAccount(state, action.payload.relationship.id) : state;
case NOTIFICATION_REQUEST_FETCH_REQUEST:
return state.set('current', initialState.get('current').set('isLoading', true));
case NOTIFICATION_REQUEST_FETCH_SUCCESS: