Make pinning and unpinning directly modify state (#37831)

This commit is contained in:
Echo authored and GitHub committed 2026-02-11 16:58:00 +00:00
1 parent 9129f98776
commit ca9966ce2f
3 files changed
+105 -59

No files matched your search

+34 -14
View File
@@ -20,7 +20,12 @@ import {
TIMELINE_GAP,
disconnectTimeline,
} from '../actions/timelines';
import { timelineDelete, isTimelineKeyPinned, isNonStatusId } from '../actions/timelines_typed';
import {
timelineDelete,
timelineDeleteStatus,
isTimelineKeyPinned,
isNonStatusId,
} from '../actions/timelines_typed';
import { compareId } from '../compare_id';
const initialState = ImmutableMap();
@@ -145,6 +150,11 @@ const deleteStatus = (state, id, references, exclude_account = null) => {
return state;
};
const deleteStatusFromTimeline = (state, statusId, timelineKey) => {
const helper = list => list.filterNot((status) => status === statusId);
return state.updateIn([timelineKey, 'items'], helper).updateIn([timelineKey, 'pendingItems'], helper);
}
const clearTimeline = (state, timeline) => {
return state.set(timeline, initialTimeline);
};
@@ -200,25 +210,12 @@ export default function timelines(state = initialState, action) {
return expandNormalizedTimeline(state, action.timeline, fromJS(action.statuses), action.next, action.partial, action.isLoadingRecent, action.usePendingItems);
case TIMELINE_UPDATE:
return updateTimeline(state, action.timeline, fromJS(action.status), action.usePendingItems);
case timelineDelete.type:
return deleteStatus(state, action.payload.statusId, action.payload.references, action.payload.reblogOf);
case TIMELINE_CLEAR:
return clearTimeline(state, action.timeline);
case blockAccountSuccess.type:
case muteAccountSuccess.type:
return filterTimelines(state, action.payload.relationship, action.payload.statuses);
case unfollowAccountSuccess.type:
return filterTimeline('home', state, action.payload.relationship, action.payload.statuses);
case TIMELINE_SCROLL_TOP:
return updateTop(state, action.timeline, action.top);
case TIMELINE_CONNECT:
return state.update(action.timeline, initialTimeline, map => reconnectTimeline(map, action.usePendingItems));
case disconnectTimeline.type:
return state.update(
action.payload.timeline,
initialTimeline,
map => map.set('online', false).update(action.payload.usePendingItems ? 'pendingItems' : 'items', items => items.first() ? items.unshift(TIMELINE_GAP) : items),
);
case TIMELINE_MARK_AS_PARTIAL:
return state.update(
action.timeline,
@@ -238,6 +235,29 @@ export default function timelines(state = initialState, action) {
})
);
default:
if (timelineDelete.match(action)) {
return deleteStatus(state, action.payload.statusId, action.payload.references, action.payload.reblogOf);
} else if (timelineDeleteStatus.match(action)) {
return deleteStatusFromTimeline(state, action.payload.statusId, action.payload.timelineKey);
} else if (blockAccountSuccess.match(action) || muteAccountSuccess.match(action)) {
return filterTimelines(state, action.payload.relationship, action.payload.statuses);
} else if (unfollowAccountSuccess.match(action)) {
return filterTimeline('home', state, action.payload.relationship, action.payload.statuses);
} else if (disconnectTimeline.match(action)) {
return state.update(
action.payload.timeline,
initialTimeline,
(map) => map.set('online', false).update(
action.payload.usePendingItems
? 'pendingItems'
: 'items',
items => items.first()
? items.unshift(TIMELINE_GAP)
: items
),
);
}
return state;
}
}