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 @@ -13,7 +13,7 @@ import { extractUserMentionsFromText } from './mention-utils.js'; import { getMessageTitle, isInvalidSidebarSource } from './message-utils.js'; import { relationshipBlockedInEitherDirection } from './relationship-utils.js'; -import { useForwardLookupSearchText } from './search-utils.js'; +import { useForwardLookupSearchText, useSearchUsers } from './search-utils.js'; import threadWatcher from './thread-watcher.js'; import { fetchMostRecentMessagesActionTypes, @@ -129,6 +129,7 @@ type DispatchActionPromise, } from '../utils/redux-promise-utils.js'; import { useSelector } from '../utils/redux-utils.js'; +import { usingCommServicesAccessToken } from '../utils/services-utils.js'; import { firstLine } from '../utils/string-utils.js'; import { trimText } from '../utils/text-utils.js'; import { pendingThreadIDRegex } from '../utils/validation-utils.js'; @@ -1560,21 +1561,30 @@ searchText: string, viewerID: ?string, ): ThreadListSearchResult { - const callSearchUsers = useLegacyAshoatKeyserverCall(searchUserCall); const usersWithPersonalThread = useSelector(usersWithPersonalThreadSelector); const forwardLookupSearchText = useForwardLookupSearchText(searchText); - const searchUsers = React.useCallback( + + const filterAndSetUserResults = React.useCallback( + (userInfos: $ReadOnlyArray) => { + const usersResults = userInfos.filter( + info => !usersWithPersonalThread.has(info.id) && info.id !== viewerID, + ); + setUsersSearchResults(usersResults); + }, + [usersWithPersonalThread, viewerID], + ); + + const legacyCallSearchUsers = useLegacyAshoatKeyserverCall(searchUserCall); + const legacySearchUsers = React.useCallback( async (usernamePrefix: string) => { if (usernamePrefix.length === 0) { - return ([]: GlobalAccountUserInfo[]); + filterAndSetUserResults([]); } - const { userInfos } = await callSearchUsers(usernamePrefix); - return userInfos.filter( - info => !usersWithPersonalThread.has(info.id) && info.id !== viewerID, - ); + const { userInfos } = await legacyCallSearchUsers(usernamePrefix); + filterAndSetUserResults(userInfos); }, - [callSearchUsers, usersWithPersonalThread, viewerID], + [filterAndSetUserResults, legacyCallSearchUsers], ); const [threadSearchResults, setThreadSearchResults] = React.useState( @@ -1588,10 +1598,23 @@ void (async () => { const results = threadSearchIndex.getSearchResults(searchText); setThreadSearchResults(new Set(results)); - const usersResults = await searchUsers(forwardLookupSearchText); - setUsersSearchResults(usersResults); + if (!usingCommServicesAccessToken) { + await legacySearchUsers(forwardLookupSearchText); + } })(); - }, [searchText, forwardLookupSearchText, threadSearchIndex, searchUsers]); + }, [ + searchText, + forwardLookupSearchText, + threadSearchIndex, + legacySearchUsers, + ]); + + const identitySearchUsers = useSearchUsers(forwardLookupSearchText); + React.useEffect(() => { + if (usingCommServicesAccessToken) { + filterAndSetUserResults(identitySearchUsers); + } + }, [filterAndSetUserResults, identitySearchUsers]); return { threadSearchResults, usersSearchResults }; }