From 1153327c7566f6a429bd05780fe09d954615ecdc Mon Sep 17 00:00:00 2001 From: Hampus Date: Tue, 25 Aug 2026 12:57:06 +0200 Subject: [PATCH] feat(app): follow the newest forward target for mention autocomplete (#2001) --- .../dialogs/shared/ForwardChannelSelection.ts | 9 ++++++++ .../components/modals/ForwardModal.tsx | 23 ++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/fluxer_app/src/features/app/components/dialogs/shared/ForwardChannelSelection.ts b/fluxer_app/src/features/app/components/dialogs/shared/ForwardChannelSelection.ts index 3ff7cb81f..8be59a9e4 100644 --- a/fluxer_app/src/features/app/components/dialogs/shared/ForwardChannelSelection.ts +++ b/fluxer_app/src/features/app/components/dialogs/shared/ForwardChannelSelection.ts @@ -27,6 +27,7 @@ export interface ForwardChannelSelectionState { readonly handleToggleChannel: (channelId: string) => void; readonly isChannelSelectionDisabled: (option: ForwardChannelOption) => boolean; readonly maxSelections: number; + readonly mostRecentlySelectedChannelId: string | null; readonly searchQuery: string; readonly selectedChannelIds: ReadonlySet; readonly setSearchQuery: Dispatch>; @@ -104,12 +105,20 @@ export function useForwardChannelSelection({ () => selectedChannelOptions.filter((option) => option.slowmodeRemainingMs > 0), [selectedChannelOptions], ); + const mostRecentlySelectedChannelId = useMemo(() => { + let mostRecent: string | null = null; + for (const channelId of selectedChannelIds) { + mostRecent = channelId; + } + return mostRecent; + }, [selectedChannelIds]); return { filteredChannels, handleToggleChannel, isChannelSelectionDisabled, maxSelections, + mostRecentlySelectedChannelId, searchQuery, selectedChannelIds, setSearchQuery, diff --git a/fluxer_app/src/features/messaging/components/modals/ForwardModal.tsx b/fluxer_app/src/features/messaging/components/modals/ForwardModal.tsx index 9cdd28a5c..a390d2a17 100644 --- a/fluxer_app/src/features/messaging/components/modals/ForwardModal.tsx +++ b/fluxer_app/src/features/messaging/components/modals/ForwardModal.tsx @@ -184,6 +184,7 @@ export const ForwardModal = observer( filteredChannels, handleToggleChannel, isChannelSelectionDisabled, + mostRecentlySelectedChannelId, searchQuery, selectedChannelIds, setSearchQuery, @@ -195,7 +196,6 @@ export const ForwardModal = observer( message, mediaSelection: mediaSelectionCapability, }); - const [optionalMessage, setOptionalMessage] = useState(''); const [actualOptionalMessage, setActualOptionalMessage] = useState(''); const [isForwarding, setIsForwarding] = useState(false); const [expressionPickerOpen, setExpressionPickerOpen] = useState(false); @@ -216,9 +216,15 @@ export const ForwardModal = observer( dataFlx: 'messaging.forward-modal.optional-message-too-long.generic-error-modal', }); }, [i18n]); - const channel = resolveForwardSourceChannel(sourceChannel, message.channelId); - const handleCommentChange = useCallback((display: string, _segments: Array, wire: string) => { - setOptionalMessage(display); + const sourceForwardChannel = resolveForwardSourceChannel(sourceChannel, message.channelId); + const composerChannel = useMemo(() => { + if (mostRecentlySelectedChannelId == null) { + return null; + } + const selectedChannel = Channels.getChannel(mostRecentlySelectedChannelId); + return selectedChannel == null ? null : selectedChannel; + }, [mostRecentlySelectedChannelId]); + const handleCommentChange = useCallback((_display: string, _segments: Array, wire: string) => { setActualOptionalMessage(wire); }, []); const isCommentOverLimit = actualOptionalMessage.length > user.maxMessageLength; @@ -269,10 +275,11 @@ export const ForwardModal = observer( setIsForwarding(true); try { let actualMessage: string | undefined; - if (!isCommentComposerDisabled && optionalMessage.trim().length > 0) { - actualMessage = actualOptionalMessage; + const trimmedOptionalMessage = actualOptionalMessage.trim(); + if (!isCommentComposerDisabled && trimmedOptionalMessage.length > 0) { + actualMessage = trimmedOptionalMessage; } - const guildId = resolveForwardReferenceGuildId(channel, message); + const guildId = resolveForwardReferenceGuildId(sourceForwardChannel, message); let attachmentIds: ReadonlyArray | undefined; let embedIndices: ReadonlyArray | undefined; if (mediaSelection !== undefined) { @@ -509,7 +516,7 @@ export const ForwardModal = observer( initialValue="" initialSegments={EMPTY_FORWARD_COMMENT_SEGMENTS} className={modalStyles.richInput} - channel={channel} + channel={composerChannel} disabled={isCommentComposerDisabled} markdown={true} singleLine={false}