Changeset View
Changeset View
Standalone View
Standalone View
lib/shared/mention-utils.js
Show First 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | return usersInThread | ||||
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, resolvedThredMembers, usernamePrefix, viewerID]); | ||||
} | } | ||||
function getMentionTypeaheadChatSuggestions( | function useMentionTypeaheadChatSuggestions( | ||||
chatSearchIndex: SentencePrefixSearchIndex, | chatSearchIndex: SentencePrefixSearchIndex, | ||||
chatMentionCandidates: ChatMentionCandidates, | chatMentionCandidates: ChatMentionCandidates, | ||||
chatNamePrefix: string, | typeaheadMatchedStrings: ?TypeaheadMatchedStrings, | ||||
): $ReadOnlyArray<MentionTypeaheadChatSuggestionItem> { | ): $ReadOnlyArray<MentionTypeaheadChatSuggestionItem> { | ||||
const chatNamePrefix: ?string = typeaheadMatchedStrings?.query; | |||||
return React.useMemo(() => { | |||||
const result = []; | const result = []; | ||||
if (chatNamePrefix === undefined || chatNamePrefix === null) { | |||||
return result; | |||||
} | |||||
const threadIDs = chatSearchIndex.getSearchResults(chatNamePrefix); | const threadIDs = chatSearchIndex.getSearchResults(chatNamePrefix); | ||||
for (const threadID of threadIDs) { | for (const threadID of threadIDs) { | ||||
if (!chatMentionCandidates[threadID]) { | if (!chatMentionCandidates[threadID]) { | ||||
continue; | continue; | ||||
} | } | ||||
result.push({ | result.push({ | ||||
type: 'chat', | type: 'chat', | ||||
threadInfo: chatMentionCandidates[threadID], | threadInfo: chatMentionCandidates[threadID], | ||||
}); | }); | ||||
} | } | ||||
return result; | return result; | ||||
}, [chatSearchIndex, chatMentionCandidates, chatNamePrefix]); | |||||
} | } | ||||
function getNewTextAndSelection( | function getNewTextAndSelection( | ||||
textBeforeAtSymbol: string, | textBeforeAtSymbol: string, | ||||
entireText: string, | entireText: string, | ||||
query: string, | query: string, | ||||
suggestionText: string, | suggestionText: string, | ||||
): { | ): { | ||||
Show All 30 Lines | ): $ReadOnlyArray<RelativeMemberInfo> { | ||||
}, [threadInfo, parentThreadInfo]); | }, [threadInfo, parentThreadInfo]); | ||||
} | } | ||||
export { | export { | ||||
markdownUserMentionRegex, | markdownUserMentionRegex, | ||||
isUserMentioned, | isUserMentioned, | ||||
extractUserMentionsFromText, | extractUserMentionsFromText, | ||||
useMentionTypeaheadUserSuggestions, | useMentionTypeaheadUserSuggestions, | ||||
getMentionTypeaheadChatSuggestions, | useMentionTypeaheadChatSuggestions, | ||||
getNewTextAndSelection, | getNewTextAndSelection, | ||||
getTypeaheadRegexMatches, | getTypeaheadRegexMatches, | ||||
useUserMentionsCandidates, | useUserMentionsCandidates, | ||||
chatMentionRegex, | chatMentionRegex, | ||||
encodeChatMentionText, | encodeChatMentionText, | ||||
decodeChatMentionText, | decodeChatMentionText, | ||||
getRawChatMention, | getRawChatMention, | ||||
renderChatMentionsWithAltText, | renderChatMentionsWithAltText, | ||||
}; | }; |