feat(app): follow the newest forward target for mention autocomplete (#2001)

This commit is contained in:
Hampus authored and GitHub committed 2026-08-25 12:57:06 +02:00
1 parent 42e45a0e3a
commit 1153327c75
2 files changed
+24 -8

No files matched your search

@@ -27,6 +27,7 @@ export interface ForwardChannelSelectionState {
readonly handleToggleChannel: (channelId: string) => void; readonly handleToggleChannel: (channelId: string) => void;
readonly isChannelSelectionDisabled: (option: ForwardChannelOption) => boolean; readonly isChannelSelectionDisabled: (option: ForwardChannelOption) => boolean;
readonly maxSelections: number; readonly maxSelections: number;
readonly mostRecentlySelectedChannelId: string | null;
readonly searchQuery: string; readonly searchQuery: string;
readonly selectedChannelIds: ReadonlySet<string>; readonly selectedChannelIds: ReadonlySet<string>;
readonly setSearchQuery: Dispatch<SetStateAction<string>>; readonly setSearchQuery: Dispatch<SetStateAction<string>>;
@@ -104,12 +105,20 @@ export function useForwardChannelSelection({
() => selectedChannelOptions.filter((option) => option.slowmodeRemainingMs > 0), () => selectedChannelOptions.filter((option) => option.slowmodeRemainingMs > 0),
[selectedChannelOptions], [selectedChannelOptions],
); );
const mostRecentlySelectedChannelId = useMemo(() => {
let mostRecent: string | null = null;
for (const channelId of selectedChannelIds) {
mostRecent = channelId;
}
return mostRecent;
}, [selectedChannelIds]);
return { return {
filteredChannels, filteredChannels,
handleToggleChannel, handleToggleChannel,
isChannelSelectionDisabled, isChannelSelectionDisabled,
maxSelections, maxSelections,
mostRecentlySelectedChannelId,
searchQuery, searchQuery,
selectedChannelIds, selectedChannelIds,
setSearchQuery, setSearchQuery,
@@ -184,6 +184,7 @@ export const ForwardModal = observer(
filteredChannels, filteredChannels,
handleToggleChannel, handleToggleChannel,
isChannelSelectionDisabled, isChannelSelectionDisabled,
mostRecentlySelectedChannelId,
searchQuery, searchQuery,
selectedChannelIds, selectedChannelIds,
setSearchQuery, setSearchQuery,
@@ -195,7 +196,6 @@ export const ForwardModal = observer(
message, message,
mediaSelection: mediaSelectionCapability, mediaSelection: mediaSelectionCapability,
}); });
const [optionalMessage, setOptionalMessage] = useState('');
const [actualOptionalMessage, setActualOptionalMessage] = useState(''); const [actualOptionalMessage, setActualOptionalMessage] = useState('');
const [isForwarding, setIsForwarding] = useState(false); const [isForwarding, setIsForwarding] = useState(false);
const [expressionPickerOpen, setExpressionPickerOpen] = 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', dataFlx: 'messaging.forward-modal.optional-message-too-long.generic-error-modal',
}); });
}, [i18n]); }, [i18n]);
const channel = resolveForwardSourceChannel(sourceChannel, message.channelId); const sourceForwardChannel = resolveForwardSourceChannel(sourceChannel, message.channelId);
const handleCommentChange = useCallback((display: string, _segments: Array<MentionSegment>, wire: string) => { const composerChannel = useMemo(() => {
setOptionalMessage(display); if (mostRecentlySelectedChannelId == null) {
return null;
}
const selectedChannel = Channels.getChannel(mostRecentlySelectedChannelId);
return selectedChannel == null ? null : selectedChannel;
}, [mostRecentlySelectedChannelId]);
const handleCommentChange = useCallback((_display: string, _segments: Array<MentionSegment>, wire: string) => {
setActualOptionalMessage(wire); setActualOptionalMessage(wire);
}, []); }, []);
const isCommentOverLimit = actualOptionalMessage.length > user.maxMessageLength; const isCommentOverLimit = actualOptionalMessage.length > user.maxMessageLength;
@@ -269,10 +275,11 @@ export const ForwardModal = observer(
setIsForwarding(true); setIsForwarding(true);
try { try {
let actualMessage: string | undefined; let actualMessage: string | undefined;
if (!isCommentComposerDisabled && optionalMessage.trim().length > 0) { const trimmedOptionalMessage = actualOptionalMessage.trim();
actualMessage = actualOptionalMessage; if (!isCommentComposerDisabled && trimmedOptionalMessage.length > 0) {
actualMessage = trimmedOptionalMessage;
} }
const guildId = resolveForwardReferenceGuildId(channel, message); const guildId = resolveForwardReferenceGuildId(sourceForwardChannel, message);
let attachmentIds: ReadonlyArray<string> | undefined; let attachmentIds: ReadonlyArray<string> | undefined;
let embedIndices: ReadonlyArray<number> | undefined; let embedIndices: ReadonlyArray<number> | undefined;
if (mediaSelection !== undefined) { if (mediaSelection !== undefined) {
@@ -509,7 +516,7 @@ export const ForwardModal = observer(
initialValue="" initialValue=""
initialSegments={EMPTY_FORWARD_COMMENT_SEGMENTS} initialSegments={EMPTY_FORWARD_COMMENT_SEGMENTS}
className={modalStyles.richInput} className={modalStyles.richInput}
channel={channel} channel={composerChannel}
disabled={isCommentComposerDisabled} disabled={isCommentComposerDisabled}
markdown={true} markdown={true}
singleLine={false} singleLine={false}