diff --git a/lib/shared/thread-utils.js b/lib/shared/thread-utils.js --- a/lib/shared/thread-utils.js +++ b/lib/shared/thread-utils.js @@ -1768,12 +1768,30 @@ return chatMentionCandidatesObj; } -const emptyMentionCandidates = {}; function useThreadChatMentionCandidates( - // eslint-disable-next-line no-unused-vars threadInfo: ThreadInfo, ): ChatMentionCandidates { - return emptyMentionCandidates; + const { chatMentionCandidatesObj, communityThreadIDForGenesisThreads } = + useChatMentionCandidatesObjAndUtils(); + return React.useMemo(() => { + let communityID, + result = {}; + if (threadInfo.community === genesis.id) { + communityID = communityThreadIDForGenesisThreads[threadInfo.id]; + } else { + communityID = threadInfo.community ?? threadInfo.id; + } + if (chatMentionCandidatesObj[communityID]) { + result = { ...chatMentionCandidatesObj[communityID] }; + } + delete result[threadInfo.id]; + return result; + }, [ + chatMentionCandidatesObj, + communityThreadIDForGenesisThreads, + threadInfo.community, + threadInfo.id, + ]); } function useUserProfileThreadInfo(userInfo: ?UserInfo): ?UserProfileThreadInfo { @@ -1834,7 +1852,6 @@ ]); } -// eslint-disable-next-line no-unused-vars function useChatMentionSearchIndex(): { +[id: string]: SentencePrefixSearchIndex, } { @@ -1863,12 +1880,20 @@ }, [chatMentionCandidatesObj]); } -const emptySearchIndex = new SentencePrefixSearchIndex(); function useThreadChatMentionSearchIndex( - // eslint-disable-next-line no-unused-vars threadInfo: ThreadInfo, ): SentencePrefixSearchIndex { - return emptySearchIndex; + const chatMentionCandidatesSearchIndex = useChatMentionSearchIndex(); + const { communityThreadIDForGenesisThreads } = + useChatMentionCandidatesObjAndUtils(); + if (threadInfo.community === genesis.id) { + return chatMentionCandidatesSearchIndex[ + communityThreadIDForGenesisThreads[threadInfo.id] + ]; + } + return chatMentionCandidatesSearchIndex[ + threadInfo.community ?? threadInfo.id + ]; } export {