Changeset View
Changeset View
Standalone View
Standalone View
lib/shared/mention-utils.js
Show First 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | |||||
const useENSNamesOptions = { allAtOnce: true }; | const useENSNamesOptions = { allAtOnce: true }; | ||||
function useMentionTypeaheadUserSuggestions( | function useMentionTypeaheadUserSuggestions( | ||||
threadMembers: $ReadOnlyArray<RelativeMemberInfo>, | threadMembers: $ReadOnlyArray<RelativeMemberInfo>, | ||||
viewerID: ?string, | viewerID: ?string, | ||||
typeaheadMatchedStrings: ?TypeaheadMatchedStrings, | typeaheadMatchedStrings: ?TypeaheadMatchedStrings, | ||||
): $ReadOnlyArray<MentionTypeaheadUserSuggestionItem> { | ): $ReadOnlyArray<MentionTypeaheadUserSuggestionItem> { | ||||
const userSearchIndex = useUserSearchIndex(threadMembers); | const userSearchIndex = useUserSearchIndex(threadMembers); | ||||
const resolvedThredMembers = useENSNames(threadMembers, useENSNamesOptions); | const resolvedThreadMembers = useENSNames(threadMembers, useENSNamesOptions); | ||||
const usernamePrefix: ?string = typeaheadMatchedStrings?.query; | const usernamePrefix: ?string = typeaheadMatchedStrings?.query; | ||||
return React.useMemo(() => { | return React.useMemo(() => { | ||||
// If typeaheadMatchedStrings is undefined, we want to return no results | // If typeaheadMatchedStrings is undefined, we want to return no results | ||||
if (usernamePrefix === undefined || usernamePrefix === null) { | if (usernamePrefix === undefined || usernamePrefix === null) { | ||||
return []; | return []; | ||||
} | } | ||||
const userIDs = userSearchIndex.getSearchResults(usernamePrefix); | const userIDs = userSearchIndex.getSearchResults(usernamePrefix); | ||||
const usersInThread = threadOtherMembers(resolvedThredMembers, viewerID); | const usersInThread = threadOtherMembers(resolvedThreadMembers, viewerID); | ||||
return usersInThread | return usersInThread | ||||
.filter(user => usernamePrefix.length === 0 || userIDs.includes(user.id)) | .filter(user => usernamePrefix.length === 0 || userIDs.includes(user.id)) | ||||
.sort((userA, userB) => | .sort((userA, userB) => | ||||
stringForUserExplicit(userA).localeCompare( | stringForUserExplicit(userA).localeCompare( | ||||
stringForUserExplicit(userB), | stringForUserExplicit(userB), | ||||
), | ), | ||||
) | ) | ||||
.map(userInfo => ({ type: 'user', userInfo })); | .map(userInfo => ({ type: 'user', userInfo })); | ||||
}, [userSearchIndex, resolvedThredMembers, usernamePrefix, viewerID]); | }, [userSearchIndex, resolvedThreadMembers, usernamePrefix, viewerID]); | ||||
} | } | ||||
function useMentionTypeaheadChatSuggestions( | function useMentionTypeaheadChatSuggestions( | ||||
chatSearchIndex: SentencePrefixSearchIndex, | chatSearchIndex: SentencePrefixSearchIndex, | ||||
chatMentionCandidates: ChatMentionCandidates, | chatMentionCandidates: ChatMentionCandidates, | ||||
typeaheadMatchedStrings: ?TypeaheadMatchedStrings, | typeaheadMatchedStrings: ?TypeaheadMatchedStrings, | ||||
): $ReadOnlyArray<MentionTypeaheadChatSuggestionItem> { | ): $ReadOnlyArray<MentionTypeaheadChatSuggestionItem> { | ||||
const chatNamePrefix: ?string = typeaheadMatchedStrings?.query; | const chatNamePrefix: ?string = typeaheadMatchedStrings?.query; | ||||
▲ Show 20 Lines • Show All 76 Lines • Show Last 20 Lines |