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 @@ -5,6 +5,7 @@ import genesis from '../facts/genesis.js'; import { threadInfoSelector } from '../selectors/thread-selectors.js'; import SentencePrefixSearchIndex from '../shared/sentence-prefix-search-index.js'; +import { threadIsPending } from '../shared/thread-utils.js'; import type { ResolvedThreadInfo, ThreadInfo, @@ -47,7 +48,12 @@ const getChatMentionSearchIndex = React.useCallback( (threadInfo: ThreadInfo) => { if (threadInfo.community === genesis.id) { - return searchIndices[communityThreadIDForGenesisThreads[threadInfo.id]]; + const threadID = + threadIsPending(threadInfo.id) && threadInfo.containingThreadID + ? threadInfo.containingThreadID + : threadInfo.id; + + return searchIndices[communityThreadIDForGenesisThreads[threadID]]; } return searchIndices[threadInfo.community ?? threadInfo.id]; }, diff --git a/lib/hooks/chat-mention-hooks.js b/lib/hooks/chat-mention-hooks.js --- a/lib/hooks/chat-mention-hooks.js +++ b/lib/hooks/chat-mention-hooks.js @@ -8,6 +8,7 @@ type ChatMentionContextType, } from '../components/chat-mention-provider.react.js'; import genesis from '../facts/genesis.js'; +import { threadIsPending } from '../shared/thread-utils.js'; import type { ThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; import type { ChatMentionCandidates } from '../types/thread-types.js'; @@ -23,11 +24,20 @@ ): ChatMentionCandidates { const { communityThreadIDForGenesisThreads, chatMentionCandidatesObj } = useChatMentionContext(); + return React.useMemo(() => { - const communityID = - threadInfo.community === genesis.id - ? communityThreadIDForGenesisThreads[threadInfo.id] - : threadInfo.community ?? threadInfo.id; + let communityID; + if (threadInfo.community === genesis.id) { + const threadID = + threadIsPending(threadInfo.id) && threadInfo.containingThreadID + ? threadInfo.containingThreadID + : threadInfo.id; + + communityID = communityThreadIDForGenesisThreads[threadID]; + } else { + communityID = threadInfo.community ?? threadInfo.id; + } + const allChatsWithinCommunity = chatMentionCandidatesObj[communityID]; if (!allChatsWithinCommunity) { return {}; @@ -38,6 +48,7 @@ chatMentionCandidatesObj, communityThreadIDForGenesisThreads, threadInfo.community, + threadInfo.containingThreadID, threadInfo.id, ]); }