From e37b30d7c07203a1801d8327a39b44a377536f8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nicole=20miko=C5=82ajczyk?= Date: Thu, 5 Mar 2026 15:26:26 +0100 Subject: [PATCH] nicolium: start removing the legacy timeline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: nicole mikołajczyk --- packages/nicolium/src/actions/admin.ts | 4 - packages/nicolium/src/actions/events.ts | 11 -- packages/nicolium/src/actions/statuses.ts | 71 +--------- packages/nicolium/src/reducers/timelines.ts | 143 +------------------- 4 files changed, 3 insertions(+), 226 deletions(-) diff --git a/packages/nicolium/src/actions/admin.ts b/packages/nicolium/src/actions/admin.ts index 44861a11f..0f5f1b13d 100644 --- a/packages/nicolium/src/actions/admin.ts +++ b/packages/nicolium/src/actions/admin.ts @@ -6,7 +6,6 @@ import { useComposeStore } from '@/stores/compose'; import { useModalsStore } from '@/stores/modals'; import { filterBadges, getTagDiff } from '@/utils/badges'; -import { STATUS_FETCH_SOURCE_FAIL, type StatusesAction } from './statuses'; import { deleteFromTimelines } from './timelines'; import type { AppDispatch, RootState } from '@/store'; @@ -149,9 +148,6 @@ const redactStatus = (statusId: string) => (dispatch: AppDispatch, getState: () .getState() .actions.setComposeToStatus(status, poll, source, false, null, null, true); useModalsStore.getState().actions.openModal('COMPOSE'); - }) - .catch((error) => { - dispatch({ type: STATUS_FETCH_SOURCE_FAIL, error }); }); }; diff --git a/packages/nicolium/src/actions/events.ts b/packages/nicolium/src/actions/events.ts index 9af044226..05f1a540b 100644 --- a/packages/nicolium/src/actions/events.ts +++ b/packages/nicolium/src/actions/events.ts @@ -5,11 +5,6 @@ import { useComposeStore } from '@/stores/compose'; import toast from '@/toast'; import { importEntities } from './importer'; -import { - STATUS_FETCH_SOURCE_FAIL, - STATUS_FETCH_SOURCE_REQUEST, - STATUS_FETCH_SOURCE_SUCCESS, -} from './statuses'; import type { AppDispatch, RootState } from '@/store'; import type { CreateEventParams, Location, MediaAttachment } from 'pl-api'; @@ -95,21 +90,15 @@ const cancelEventCompose = () => { }; const initEventEdit = (statusId: string) => (dispatch: AppDispatch, getState: () => RootState) => { - dispatch({ type: STATUS_FETCH_SOURCE_REQUEST, statusId }); - return getClient(getState()) .statuses.getStatusSource(statusId) .then((response) => { - dispatch({ type: STATUS_FETCH_SOURCE_SUCCESS, statusId }); useComposeStore .getState() .actions.updateCompose(`compose-event-modal-${statusId}`, (draft) => { draft.text = response.text; }); return response; - }) - .catch((error) => { - dispatch({ type: STATUS_FETCH_SOURCE_FAIL, statusId, error }); }); }; diff --git a/packages/nicolium/src/actions/statuses.ts b/packages/nicolium/src/actions/statuses.ts index 541247ea5..23a7e48dc 100644 --- a/packages/nicolium/src/actions/statuses.ts +++ b/packages/nicolium/src/actions/statuses.ts @@ -17,17 +17,9 @@ import { deleteFromTimelines } from './timelines'; import type { NormalizedStatus as Status } from '@/normalizers/status'; import type { AppDispatch, RootState } from '@/store'; -import type { CreateStatusParams, Status as BaseStatus, ScheduledStatus } from 'pl-api'; +import type { CreateStatusParams, Status as BaseStatus } from 'pl-api'; import type { IntlShape } from 'react-intl'; -const STATUS_CREATE_REQUEST = 'STATUS_CREATE_REQUEST' as const; -const STATUS_CREATE_SUCCESS = 'STATUS_CREATE_SUCCESS' as const; -const STATUS_CREATE_FAIL = 'STATUS_CREATE_FAIL' as const; - -const STATUS_FETCH_SOURCE_REQUEST = 'STATUS_FETCH_SOURCE_REQUEST' as const; -const STATUS_FETCH_SOURCE_SUCCESS = 'STATUS_FETCH_SOURCE_SUCCESS' as const; -const STATUS_FETCH_SOURCE_FAIL = 'STATUS_FETCH_SOURCE_FAIL' as const; - const incrementReplyCount = ( params: Pick, ) => { @@ -91,13 +83,6 @@ const createStatus = if (!editedId) { incrementReplyCount(params); } - dispatch({ - type: STATUS_CREATE_REQUEST, - params, - idempotencyKey, - editing: !!editedId, - redacting, - }); } const client = getClient(getState()); @@ -124,14 +109,6 @@ const createStatus = queryClient.invalidateQueries(scheduledStatusesQueryOptions); } - dispatch({ - type: STATUS_CREATE_SUCCESS, - status, - params, - idempotencyKey, - editing: !!editedId, - }); - useContextStore .getState() .actions.deletePendingStatus( @@ -176,13 +153,6 @@ const createStatus = if (!editedId) { decrementReplyCount(params); } - dispatch({ - type: STATUS_CREATE_FAIL, - error, - params, - idempotencyKey, - editing: !!editedId, - }); throw error; }); }; @@ -195,17 +165,11 @@ const editStatus = (statusId: string) => (dispatch: AppDispatch, getState: () => ? queryClient.getQueryData(queryKeys.statuses.polls.show(status.poll_id)) : undefined; - dispatch({ type: STATUS_FETCH_SOURCE_REQUEST }); - return getClient(getState()) .statuses.getStatusSource(statusId) .then((response) => { - dispatch({ type: STATUS_FETCH_SOURCE_SUCCESS }); useComposeStore.getState().actions.setComposeToStatus(status, poll, response); useModalsStore.getState().actions.openModal('COMPOSE'); - }) - .catch((error) => { - dispatch({ type: STATUS_FETCH_SOURCE_FAIL, error }); }); }; @@ -386,39 +350,7 @@ const unfilterStatus = (statusId: string) => { ); }; -type StatusesAction = - | { - type: typeof STATUS_CREATE_REQUEST; - params: CreateStatusParams; - idempotencyKey: string; - editing: boolean; - redacting: boolean; - } - | { - type: typeof STATUS_CREATE_SUCCESS; - status: BaseStatus | ScheduledStatus; - params: CreateStatusParams; - idempotencyKey: string; - editing: boolean; - } - | { - type: typeof STATUS_CREATE_FAIL; - error: unknown; - params: CreateStatusParams; - idempotencyKey: string; - editing: boolean; - } - | { type: typeof STATUS_FETCH_SOURCE_REQUEST } - | { type: typeof STATUS_FETCH_SOURCE_SUCCESS } - | { type: typeof STATUS_FETCH_SOURCE_FAIL; error: unknown }; - export { - STATUS_CREATE_REQUEST, - STATUS_CREATE_SUCCESS, - STATUS_CREATE_FAIL, - STATUS_FETCH_SOURCE_REQUEST, - STATUS_FETCH_SOURCE_SUCCESS, - STATUS_FETCH_SOURCE_FAIL, createStatus, editStatus, fetchStatus, @@ -426,5 +358,4 @@ export { deleteStatusFromGroup, toggleMuteStatus, unfilterStatus, - type StatusesAction, }; diff --git a/packages/nicolium/src/reducers/timelines.ts b/packages/nicolium/src/reducers/timelines.ts index 54de24704..04f303cf3 100644 --- a/packages/nicolium/src/reducers/timelines.ts +++ b/packages/nicolium/src/reducers/timelines.ts @@ -1,15 +1,5 @@ import { create } from 'mutative'; -import { - ACCOUNT_BLOCK_SUCCESS, - ACCOUNT_MUTE_SUCCESS, - type AccountsAction, -} from '@/actions/accounts'; -import { - STATUS_CREATE_REQUEST, - STATUS_CREATE_SUCCESS, - type StatusesAction, -} from '@/actions/statuses'; import { TIMELINE_UPDATE, TIMELINE_DELETE, @@ -23,15 +13,8 @@ import { TIMELINE_SCROLL_TOP, type TimelineAction, } from '@/actions/timelines'; -import { findStatuses } from '@/queries/statuses/use-status'; -import type { NormalizedStatus as Status } from '@/normalizers/status'; -import type { - PaginatedResponse, - Status as BaseStatus, - Relationship, - CreateStatusParams, -} from 'pl-api'; +import type { PaginatedResponse, Status as BaseStatus } from 'pl-api'; type ImportPosition = 'start' | 'end'; @@ -213,37 +196,6 @@ const updateTop = (state: State, timelineId: string, top: boolean) => { }); }; -const isReblogOf = (reblog: Pick, status: Pick) => - reblog.reblog_id === status.id; - -const buildReferencesTo = (status: Pick): Array<[string]> => - findStatuses((reblog) => isReblogOf(reblog, status)).map(([id]) => [id]); - -// const filterTimeline = ( -// state: State, -// timelineId: string, -// relationship: Relationship, -// statuses: Record>, -// ) => { -// const timeline = state[timelineId]; -// if (!timeline) { -// return; -// } -// timeline.items = timeline.items.filter((id) => { -// const status = statuses[id]; -// return !(status && status.account_id === relationship.id); -// }); -// }; - -const filterTimelines = (state: State, relationship: Relationship) => { - const ownedStatuses = findStatuses((status) => status.account_id === relationship.id); - - for (const [, status] of ownedStatuses) { - const references = buildReferencesTo(status); - deleteStatus(state, status.id, references, relationship.id); - } -}; - const timelineDequeue = (state: State, timelineId: string) => { updateTimeline(state, timelineId, (timeline) => { const top = timeline.top; @@ -258,97 +210,13 @@ const timelineDequeue = (state: State, timelineId: string) => { }); }; -// const timelineDisconnect = (state: State, timelineId: string) => -// state.update(timelineId, TimelineRecord(), timeline => timeline.withMutations(timeline => { -// This is causing problems. Disable for now. -// https://gitlab.com/soapbox-pub/soapbox/-/issues/716 -// timeline.set('items', addStatusId(items, null)); -// })); - -const getTimelinesForStatus = ( - status: Pick | Pick, -) => { - switch (status.visibility) { - case 'group': - return [`group:${'group' in status && status.group?.id}`]; - case 'direct': - return ['direct']; - case 'public': - return ['home', 'public:local', 'public', 'bubble']; - default: - return ['home']; - } -}; - -// Given an OrderedSet of IDs, replace oldId with newId maintaining its position -const replaceId = (ids: Array, oldId: string, newId: string) => { - if (ids.includes(newId)) return false; - - let found = false; - const index = ids.indexOf(oldId); - - if (index > -1) { - ids[index] = newId; - found = true; - } - - return found; -}; - -const importPendingStatus = (state: State, params: CreateStatusParams, idempotencyKey: string) => { - const statusId = `末pending-${idempotencyKey}`; - - const timelineIds = getTimelinesForStatus(params); - - timelineIds.forEach((timelineId) => { - updateTimelineQueue(state, timelineId, statusId); - }); -}; - -const replacePendingStatus = (state: State, idempotencyKey: string, newId: string) => { - const oldId = `末pending-${idempotencyKey}`; - - // Loop through timelines and replace the pending status with the real one - for (const timelineId in state) { - const found = replaceId(state[timelineId].items, oldId, newId); - if (found) { - state[timelineId].queuedItems = state[timelineId].queuedItems.filter((id) => id !== oldId); - } else { - replaceId(state[timelineId].queuedItems, oldId, newId); - } - } -}; - -const importStatus = (state: State, status: BaseStatus, idempotencyKey: string) => { - replacePendingStatus(state, idempotencyKey, status.id); - - const timelineIds = getTimelinesForStatus(status); - - timelineIds.forEach((timelineId) => { - appendStatus(state, timelineId, status.id); - }); -}; - const handleExpandFail = (state: State, timelineId: string) => { setLoading(state, timelineId, false); setFailed(state, timelineId, true); }; -const timelines = ( - state: State = initialState, - action: AccountsAction | StatusesAction | TimelineAction, -): State => { +const timelines = (state: State = initialState, action: TimelineAction): State => { switch (action.type) { - case STATUS_CREATE_REQUEST: - if (action.params.scheduled_at) return state; - return create(state, (draft) => { - importPendingStatus(draft, action.params, action.idempotencyKey); - }); - case STATUS_CREATE_SUCCESS: - if ('params' in action.status || action.editing) return state; - return create(state, (draft) => { - importStatus(draft, action.status as BaseStatus, action.idempotencyKey); - }); case TIMELINE_EXPAND_REQUEST: return create(state, (draft) => { setLoading(draft, action.timeline, true); @@ -386,13 +254,6 @@ const timelines = ( return create(state, (draft) => { clearTimeline(draft, action.timeline); }); - case ACCOUNT_BLOCK_SUCCESS: - case ACCOUNT_MUTE_SUCCESS: - return create(state, (draft) => { - filterTimelines(draft, action.relationship); - }); - // case ACCOUNT_UNFOLLOW_SUCCESS: - // return filterTimeline(state, 'home', action.relationship, action.statuses); case TIMELINE_SCROLL_TOP: return create(state, (draft) => { updateTop(draft, action.timeline, action.top);