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 @@ -19,6 +19,12 @@ import { getNameForThreadEntity } from '../utils/entity-text.js'; import { useSelector } from '../utils/redux-utils.js'; +type BaseThreadInfo = { + +id: string, + +containingThreadID?: ?string, + ... +}; + type Props = { +children: React.Node, }; @@ -26,7 +32,9 @@ +getChatMentionSearchIndex: ( threadInfo: ThreadInfo, ) => ?SentencePrefixSearchIndex, - +getCommunityThreadIDForGenesisThreads: (threadInfo: ThreadInfo) => string, + +getCommunityThreadIDForGenesisThreads: ( + threadInfo: BaseThreadInfo, + ) => string, +chatMentionCandidatesObj: ChatMentionCandidatesObj, }; @@ -217,7 +225,7 @@ function useChatMentionCandidatesObjAndUtils(): { chatMentionCandidatesObj: ChatMentionCandidatesObj, - getCommunityThreadIDForGenesisThreads: (threadInfo: ThreadInfo) => string, + getCommunityThreadIDForGenesisThreads: (threadInfo: BaseThreadInfo) => string, } { const threadInfos = useSelector(threadInfoSelector); const resolvedThreadInfos = useResolvedThreadInfosObj( @@ -231,7 +239,7 @@ ); const getCommunityThreadIDForGenesisThreads = React.useCallback( - (threadInfo: ThreadInfo): string => { + (threadInfo: BaseThreadInfo): string => { const threadID = threadIsPending(threadInfo.id) && threadInfo.containingThreadID ? threadInfo.containingThreadID diff --git a/lib/hooks/thread-hooks.js b/lib/hooks/thread-hooks.js --- a/lib/hooks/thread-hooks.js +++ b/lib/hooks/thread-hooks.js @@ -3,8 +3,8 @@ import * as React from 'react'; import { useChatMentionContext } from './chat-mention-hooks.js'; +import genesis from '../facts/genesis.js'; import { childThreadInfos } from '../selectors/thread-selectors.js'; -import { getCommunity } from '../shared/thread-utils.js'; import type { ResolvedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; import { useSelector } from '../utils/redux-utils.js'; @@ -13,14 +13,20 @@ } { const childThreadInfosMap = useSelector(childThreadInfos); - const { chatMentionCandidatesObj } = useChatMentionContext(); + const { getCommunityThreadIDForGenesisThreads, chatMentionCandidatesObj } = + useChatMentionContext(); return React.useMemo(() => { const result: { [id: string]: $ReadOnlyArray } = {}; for (const parentThreadID in childThreadInfosMap) { result[parentThreadID] = childThreadInfosMap[parentThreadID] .map(rawThreadInfo => { - const community = getCommunity(rawThreadInfo); + const communityThreadIDForGenesisThreads = + getCommunityThreadIDForGenesisThreads(rawThreadInfo); + const community = + rawThreadInfo.community === genesis().id + ? communityThreadIDForGenesisThreads + : rawThreadInfo.community ?? rawThreadInfo.id; if (!community) { return undefined; } @@ -33,7 +39,11 @@ .filter(Boolean); } return result; - }, [childThreadInfosMap, chatMentionCandidatesObj]); + }, [ + childThreadInfosMap, + getCommunityThreadIDForGenesisThreads, + chatMentionCandidatesObj, + ]); } export { useChildThreadInfosMap };