diff --git a/lib/components/chat-mention-provider.react.js b/lib/components/chat-mention-provider.react.js --- a/lib/components/chat-mention-provider.react.js +++ b/lib/components/chat-mention-provider.react.js @@ -7,8 +7,8 @@ import SentencePrefixSearchIndex from '../shared/sentence-prefix-search-index.js'; import { threadTypes } from '../types/thread-types-enum.js'; import type { - ChatMentionCandidates, ChatMentionCandidatesObj, + ChatMentionCandidate, ResolvedThreadInfo, ThreadInfo, } from '../types/thread-types.js'; @@ -80,7 +80,7 @@ } { const result: { [string]: { - [string]: ResolvedThreadInfo, + [string]: ChatMentionCandidate, }, } = {}; const visitedGenesisThreads = new Set(); @@ -91,15 +91,20 @@ if (!currentThreadCommunity) { if (!result[currentThreadID]) { result[currentThreadID] = { - [currentThreadID]: currentResolvedThreadInfo, + [currentThreadID]: { + threadInfo: currentResolvedThreadInfo, + rawChatName: threadInfos[currentThreadID].uiName, + }, }; } continue; } if (!result[currentThreadCommunity]) { result[currentThreadCommunity] = {}; - result[currentThreadCommunity][currentThreadCommunity] = - resolvedThreadInfos[currentThreadCommunity]; + result[currentThreadCommunity][currentThreadCommunity] = { + threadInfo: resolvedThreadInfos[currentThreadCommunity], + rawChatName: threadInfos[currentThreadCommunity].uiName, + }; } // Handle GENESIS community case: mentioning inside GENESIS should only // show chats and threads inside the top level that is below GENESIS. @@ -146,7 +151,10 @@ result[lastThreadInTraversePath.id] = {}; } for (const threadInfo of threadTraversePath) { - result[lastThreadInTraversePath.id][threadInfo.id] = threadInfo; + result[lastThreadInTraversePath.id][threadInfo.id] = { + threadInfo, + rawChatName: threadInfos[threadInfo.id].uiName, + }; communityThreadIDForGenesisThreads[threadInfo.id] = lastThreadInTraversePath.id; } @@ -154,8 +162,10 @@ lastThreadInTraversePath.type !== threadTypes.PERSONAL && lastThreadInTraversePath.type !== threadTypes.PRIVATE ) { - result[genesis.id][lastThreadInTraversePath.id] = - lastThreadInTraversePath; + result[genesis.id][lastThreadInTraversePath.id] = { + threadInfo: lastThreadInTraversePath, + rawChatName: threadInfos[lastThreadInTraversePath.id].uiName, + }; } } else { if ( @@ -170,14 +180,20 @@ for (const threadInfo of threadTraversePath) { result[lastThreadInTraversePathParentCommunityThreadID][ threadInfo.id - ] = threadInfo; + ] = { + threadInfo, + rawChatName: threadInfos[threadInfo.id].uiName, + }; communityThreadIDForGenesisThreads[threadInfo.id] = lastThreadInTraversePathParentCommunityThreadID; } } continue; } - result[currentThreadCommunity][currentThreadID] = currentResolvedThreadInfo; + result[currentThreadCommunity][currentThreadID] = { + threadInfo: currentResolvedThreadInfo, + rawChatName: threadInfos[currentThreadID].uiName, + }; } return { chatMentionCandidatesObj: result, @@ -193,7 +209,7 @@ function useChatMentionCandidatesObjAndUtils(): { chatMentionCandidatesObj: ChatMentionCandidatesObj, - resolvedThreadInfos: ChatMentionCandidates, + resolvedThreadInfos: { +[id: string]: ResolvedThreadInfo }, communityThreadIDForGenesisThreads: { +[id: string]: string }, } { const threadInfos = useSelector(threadInfoSelector); @@ -226,7 +242,9 @@ for (const threadID in chatMentionCandidatesObj[communityThreadID]) { searchIndexEntries.push({ id: threadID, - uiName: chatMentionCandidatesObj[communityThreadID][threadID].uiName, + uiName: + chatMentionCandidatesObj[communityThreadID][threadID].threadInfo + .uiName, }); } // Sort the keys so that the order of the search result is consistent diff --git a/lib/shared/markdown.js b/lib/shared/markdown.js --- a/lib/shared/markdown.js +++ b/lib/shared/markdown.js @@ -289,7 +289,8 @@ content: string, hasAccessToChat: boolean, } { - const threadInfo = chatMentionCandidates[capture[3]]; + const chatMentionCandidate = chatMentionCandidates[capture[3]]; + const threadInfo = chatMentionCandidate?.threadInfo; const threadName = threadInfo?.uiName ?? decodeChatMentionText(capture[4]); const content = `${capture[1]}@${threadName}`; return { diff --git a/lib/shared/mention-utils.js b/lib/shared/mention-utils.js --- a/lib/shared/mention-utils.js +++ b/lib/shared/mention-utils.js @@ -11,6 +11,7 @@ import { threadTypes } from '../types/thread-types-enum.js'; import type { ChatMentionCandidates, + ChatMentionCandidate, RelativeMemberInfo, ThreadInfo, ResolvedThreadInfo, @@ -34,7 +35,7 @@ type MentionTypeaheadChatSuggestionItem = { +type: 'chat', - +threadInfo: ResolvedThreadInfo, + +chatMentionCandidate: ChatMentionCandidate, }; export type MentionTypeaheadSuggestionItem = @@ -153,9 +154,10 @@ if (!chatMentionCandidates[threadID]) { continue; } + const chatMentionCandidate = chatMentionCandidates[threadID]; result.push({ type: 'chat', - threadInfo: chatMentionCandidates[threadID], + chatMentionCandidate, }); } return result; diff --git a/lib/types/thread-types.js b/lib/types/thread-types.js --- a/lib/types/thread-types.js +++ b/lib/types/thread-types.js @@ -489,8 +489,12 @@ export type ThreadStoreThreadInfos = LegacyRawThreadInfos; +export type ChatMentionCandidate = { + +threadInfo: ResolvedThreadInfo, + +rawChatName: string | ThreadEntity, +}; export type ChatMentionCandidates = { - +[id: string]: ResolvedThreadInfo, + +[id: string]: ChatMentionCandidate, }; export type ChatMentionCandidatesObj = { +[id: string]: ChatMentionCandidates, diff --git a/native/chat/mention-typeahead-tooltip-button.react.js b/native/chat/mention-typeahead-tooltip-button.react.js --- a/native/chat/mention-typeahead-tooltip-button.react.js +++ b/native/chat/mention-typeahead-tooltip-button.react.js @@ -28,10 +28,10 @@ ); typeaheadTooltipButtonText = item.actionButtonContent.userInfo.username; } else if (item.actionButtonContent.type === 'chat') { - typeaheadTooltipButtonText = item.actionButtonContent.threadInfo.uiName; - avatarComponent = ( - - ); + const chatMentionCandidate = item.actionButtonContent.chatMentionCandidate; + const { threadInfo } = chatMentionCandidate; + typeaheadTooltipButtonText = threadInfo.uiName; + avatarComponent = ; } return ( diff --git a/native/utils/typeahead-utils.js b/native/utils/typeahead-utils.js --- a/native/utils/typeahead-utils.js +++ b/native/utils/typeahead-utils.js @@ -92,7 +92,8 @@ }, }); } else if (suggestion.type === 'chat') { - const { threadInfo } = suggestion; + const { chatMentionCandidate } = suggestion; + const { threadInfo } = chatMentionCandidate; const mentionText = getRawChatMention(threadInfo); actions.push({ key: threadInfo.id, @@ -106,7 +107,7 @@ }), actionButtonContent: { type: 'chat', - threadInfo, + chatMentionCandidate, }, }); } diff --git a/web/utils/typeahead-utils.js b/web/utils/typeahead-utils.js --- a/web/utils/typeahead-utils.js +++ b/web/utils/typeahead-utils.js @@ -143,10 +143,11 @@ }, }); } else if (suggestion.type === 'chat') { - const suggestedChat = suggestion.threadInfo; - const mentionText = getRawChatMention(suggestedChat); + const { chatMentionCandidate } = suggestion; + const { threadInfo } = chatMentionCandidate; + const mentionText = getRawChatMention(threadInfo); actions.push({ - key: suggestedChat.id, + key: threadInfo.id, execute: () => mentionTypeaheadTooltipActionExecuteHandler({ textBeforeAtSymbol, @@ -158,7 +159,7 @@ }), actionButtonContent: { type: 'chat', - threadInfo: suggestedChat, + chatMentionCandidate, }, }); } @@ -197,10 +198,10 @@ ); typeaheadButtonText = `@${stringForUserExplicit(suggestedUser)}`; } else if (actionButtonContent.type === 'chat') { - const suggestedChat = actionButtonContent.threadInfo; - avatarComponent = ( - - ); + const chatMentionCandidate = actionButtonContent.chatMentionCandidate; + const { threadInfo } = chatMentionCandidate; + const suggestedChat = threadInfo; + avatarComponent = ; typeaheadButtonText = `@${suggestedChat.uiName}`; }