diff --git a/app/javascript/flavours/glitch/actions/compose.js b/app/javascript/flavours/glitch/actions/compose.js index 8f66e5c668..dbfd836bbe 100644 --- a/app/javascript/flavours/glitch/actions/compose.js +++ b/app/javascript/flavours/glitch/actions/compose.js @@ -15,6 +15,7 @@ import { useEmoji } from './emojis'; import { importFetchedAccounts, importFetchedStatus } from './importer'; import { openModal } from './modal'; import { updateTimeline } from './timelines'; +import { insertStatusIntoAccountTimelines } from './timelines_typed'; /** @type {AbortController | undefined} */ let fetchComposeSuggestionsAccountsController; @@ -206,14 +207,14 @@ export function directCompose(account) { */ export function submitCompose(overridePrivacy = null, successCallback = undefined) { return function (dispatch, getState) { - let status = getState().getIn(['compose', 'text'], ''); - const media = getState().getIn(['compose', 'media_attachments']); - const statusId = getState().getIn(['compose', 'id'], null); - const hasQuote = !!getState().getIn(['compose', 'quoted_status_id']); - const spoilers = getState().getIn(['compose', 'spoiler']) || getState().getIn(['local_settings', 'always_show_spoilers_field']); + const statusText = getState().getIn(['compose', 'text'], ''); + const media = getState().getIn(['compose', 'media_attachments']); + const statusId = getState().getIn(['compose', 'id'], null); + const hasQuote = !!getState().getIn(['compose', 'quoted_status_id']); + const spoilers = getState().getIn(['compose', 'spoiler']) || getState().getIn(['local_settings', 'always_show_spoilers_field']); const spoiler_text = spoilers ? getState().getIn(['compose', 'spoiler_text'], '') : ''; - const fulltext = `${spoiler_text ?? ''}${countableText(status ?? '')}`; + const fulltext = `${spoiler_text ?? ''}${countableText(statusText ?? '')}`; const hasText = fulltext.trim().length > 0; if (!(hasText || media.size !== 0 || (hasQuote && spoiler_text?.length))) { @@ -252,7 +253,7 @@ export function submitCompose(overridePrivacy = null, successCallback = undefine url: statusId === null ? '/api/v1/statuses' : `/api/v1/statuses/${statusId}`, method: statusId === null ? 'post' : 'put', data: { - status, + status: statusText, spoiler_text, content_type: getState().getIn(['compose', 'content_type']), local_only: getState().getIn(['compose', 'advanced_options', 'do_not_federate']), @@ -276,7 +277,7 @@ export function submitCompose(overridePrivacy = null, successCallback = undefine browserHistory.goBack(); } - dispatch(insertIntoTagHistory(response.data.tags, status)); + dispatch(insertIntoTagHistory(response.data.tags, statusText)); dispatch(submitComposeSuccess({ ...response.data })); if (typeof successCallback === 'function') { successCallback(response.data); @@ -309,6 +310,8 @@ export function submitCompose(overridePrivacy = null, successCallback = undefine insertIfOnline('direct'); } + dispatch(insertStatusIntoAccountTimelines({ ...response.data })); + if (getState().getIn(['local_settings', 'show_published_toast'])) { dispatch(showAlert({ message: statusId === null ? messages.published : messages.saved, diff --git a/app/javascript/flavours/glitch/actions/timelines_typed.ts b/app/javascript/flavours/glitch/actions/timelines_typed.ts index a13522c60c..4219f7d348 100644 --- a/app/javascript/flavours/glitch/actions/timelines_typed.ts +++ b/app/javascript/flavours/glitch/actions/timelines_typed.ts @@ -3,6 +3,7 @@ import type { List as ImmutableList, Map as ImmutableMap } from 'immutable'; import { usePendingItems as preferPendingItems } from 'flavours/glitch/initial_state'; +import type { ApiStatusJSON } from '../api_types/statuses'; import type { Status } from '../models/status'; import { createAppThunk } from '../store/typed_functions'; @@ -10,6 +11,7 @@ import { expandTimeline, insertIntoTimeline, TIMELINE_NON_STATUS_MARKERS, + updateTimeline, } from './timelines'; export const expandTimelineByKey = createAppThunk( @@ -208,6 +210,34 @@ export const timelineDeleteStatus = createAction<{ timelineKey: string; }>('timelines/deleteStatus'); +export const insertStatusIntoAccountTimelines = createAppThunk( + (status: ApiStatusJSON, { dispatch, getState }) => { + const currentAccountId = getState().meta.get('me', null) as string | null; + if (!currentAccountId) { + return; + } + + const tags = status.tags.map((tag) => tag.name); + + const timelines = getState().timelines as ImmutableMap; + const accountTimelines = timelines.filter((_, key) => { + if (!key.startsWith(`account:${currentAccountId}:`)) { + return false; + } + const parsed = parseTimelineKey(key); + if (parsed?.type !== 'account' || parsed.pinned) { + return false; + } + + return !parsed.tagged || tags.includes(parsed.tagged); + }); + + accountTimelines.forEach((_, timelineKey) => { + dispatch(updateTimeline(timelineKey, status)); + }); + }, +); + export const insertPinnedStatusIntoTimelines = createAppThunk( (status: Status, { dispatch, getState }) => { const currentAccountId = getState().meta.get('me', null) as string | null; diff --git a/app/javascript/flavours/glitch/reducers/timelines.js b/app/javascript/flavours/glitch/reducers/timelines.js index cfefc15e5e..bf5e0ef1f5 100644 --- a/app/javascript/flavours/glitch/reducers/timelines.js +++ b/app/javascript/flavours/glitch/reducers/timelines.js @@ -109,15 +109,15 @@ const expandNormalizedTimeline = (state, timeline, statuses, next, isPartial, is })); }; -const updateTimeline = (state, timeline, status, usePendingItems, filtered) => { +const updateTimeline = (state, timeline, statusId, usePendingItems, filtered) => { const top = state.getIn([timeline, 'top']); if (usePendingItems || !state.getIn([timeline, 'pendingItems']).isEmpty()) { - if (state.getIn([timeline, 'pendingItems'], ImmutableList()).includes(status.get('id')) || state.getIn([timeline, 'items'], ImmutableList()).includes(status.get('id'))) { + if (state.getIn([timeline, 'pendingItems'], ImmutableList()).includes(statusId) || state.getIn([timeline, 'items'], ImmutableList()).includes(statusId)) { return state; } - state = state.update(timeline, initialTimeline, map => map.update('pendingItems', list => list.unshift(status.get('id')))); + state = state.update(timeline, initialTimeline, map => map.update('pendingItems', list => list.unshift(statusId))); if (!filtered) { state = state.updateIn([timeline, 'unread'], unread => unread + 1); @@ -127,7 +127,7 @@ const updateTimeline = (state, timeline, status, usePendingItems, filtered) => { } const ids = state.getIn([timeline, 'items'], ImmutableList()); - const includesId = ids.includes(status.get('id')); + const includesId = ids.includes(statusId); const unread = state.getIn([timeline, 'unread'], 0); if (includesId) { @@ -139,7 +139,7 @@ const updateTimeline = (state, timeline, status, usePendingItems, filtered) => { return state.update(timeline, initialTimeline, map => map.withMutations(mMap => { if (!top && !filtered) mMap.set('unread', unread + 1); if (top && ids.size > 40) newIds = newIds.take(20); - mMap.set('items', newIds.unshift(status.get('id'))); + mMap.set('items', newIds.unshift(statusId)); })); }; @@ -219,7 +219,7 @@ export default function timelines(state = initialState, action) { case TIMELINE_EXPAND_SUCCESS: 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, action.filtered); + return updateTimeline(state, action.timeline, action.status.id, action.usePendingItems, action.filtered); case TIMELINE_CLEAR: return clearTimeline(state, action.timeline); case TIMELINE_SCROLL_TOP: