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 @@ -1,10 +1,16 @@ // @flow +import invariant from 'invariant'; + import { oldValidUsernameRegexString } from './account-utils.js'; import SearchIndex from './search-index.js'; import { threadOtherMembers } from './thread-utils.js'; import { stringForUserExplicit } from './user-utils.js'; -import type { RelativeMemberInfo } from '../types/thread-types.js'; +import { + threadTypes, + type ThreadInfo, + type RelativeMemberInfo, +} from '../types/thread-types.js'; export type TypeaheadMatchedStrings = { +textBeforeAtSymbol: string, @@ -89,6 +95,17 @@ return { newText, newSelectionStart }; } +function getMentionsCandidates( + threadInfo: ThreadInfo, + parentThreadInfo: ?ThreadInfo, +): $ReadOnlyArray { + if (threadInfo.type !== threadTypes.SIDEBAR) { + return threadInfo.members; + } + invariant(parentThreadInfo, 'sidebars should have parents'); + return parentThreadInfo.members; +} + export { markdownMentionRegex, isMentioned, @@ -96,4 +113,5 @@ getTypeaheadUserSuggestions, getNewTextAndSelection, getTypeaheadRegexMatches, + getMentionsCandidates, }; diff --git a/native/chat/chat-input-bar.react.js b/native/chat/chat-input-bar.react.js --- a/native/chat/chat-input-bar.react.js +++ b/native/chat/chat-input-bar.react.js @@ -29,14 +29,12 @@ } from 'lib/actions/thread-actions.js'; import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js'; import { threadInfoSelector } from 'lib/selectors/thread-selectors.js'; -import { - relativeMemberInfoSelectorForMembersOfThread, - userStoreSearchIndex, -} from 'lib/selectors/user-selectors.js'; +import { userStoreSearchIndex } from 'lib/selectors/user-selectors.js'; import { getTypeaheadUserSuggestions, getTypeaheadRegexMatches, type Selection, + getMentionsCandidates, } from 'lib/shared/mention-utils.js'; import { localIDPrefix, trimMessage } from 'lib/shared/message-utils.js'; import SearchIndex from 'lib/shared/search-index.js'; @@ -939,15 +937,17 @@ const callJoinThread = useServerCall(joinThread); const userSearchIndex = useSelector(userStoreSearchIndex); - const mentionsCandidates = useSelector( - relativeMemberInfoSelectorForMembersOfThread(props.threadInfo.id), - ); const { parentThreadID } = props.threadInfo; const parentThreadInfo = useSelector(state => parentThreadID ? threadInfoSelector(state)[parentThreadID] : null, ); + const mentionsCandidates = getMentionsCandidates( + props.threadInfo, + parentThreadInfo, + ); + return ( + parentThreadID ? threadInfoSelector(state)[parentThreadID] : null, + ); + + const mentionsCandidates = getMentionsCandidates( + props.threadInfo, + parentThreadInfo, ); const typeaheadRegexMatches = React.useMemo( @@ -609,11 +614,6 @@ typeaheadMatchedStrings, ]); - const { parentThreadID } = props.threadInfo; - const parentThreadInfo = useSelector(state => - parentThreadID ? threadInfoSelector(state)[parentThreadID] : null, - ); - return (