Page MenuHomePhorge

D10432.1765145390.diff
No OneTemporary

Size
4 KB
Referenced Files
None
Subscribers
None

D10432.1765145390.diff

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
@@ -134,23 +134,32 @@
}, [userSearchIndex, resolvedThredMembers, usernamePrefix, viewerID]);
}
-function getMentionTypeaheadChatSuggestions(
+function useMentionTypeaheadChatSuggestions(
chatSearchIndex: SentencePrefixSearchIndex,
chatMentionCandidates: ChatMentionCandidates,
- chatNamePrefix: string,
+ typeaheadMatchedStrings: ?TypeaheadMatchedStrings,
): $ReadOnlyArray<MentionTypeaheadChatSuggestionItem> {
- const result = [];
- const threadIDs = chatSearchIndex.getSearchResults(chatNamePrefix);
- for (const threadID of threadIDs) {
- if (!chatMentionCandidates[threadID]) {
- continue;
+ const chatNamePrefix: ?string = typeaheadMatchedStrings?.query;
+
+ return React.useMemo(() => {
+ const result = [];
+
+ if (chatNamePrefix === undefined || chatNamePrefix === null) {
+ return result;
}
- result.push({
- type: 'chat',
- threadInfo: chatMentionCandidates[threadID],
- });
- }
- return result;
+
+ const threadIDs = chatSearchIndex.getSearchResults(chatNamePrefix);
+ for (const threadID of threadIDs) {
+ if (!chatMentionCandidates[threadID]) {
+ continue;
+ }
+ result.push({
+ type: 'chat',
+ threadInfo: chatMentionCandidates[threadID],
+ });
+ }
+ return result;
+ }, [chatSearchIndex, chatMentionCandidates, chatNamePrefix]);
}
function getNewTextAndSelection(
@@ -197,7 +206,7 @@
isUserMentioned,
extractUserMentionsFromText,
useMentionTypeaheadUserSuggestions,
- getMentionTypeaheadChatSuggestions,
+ useMentionTypeaheadChatSuggestions,
getNewTextAndSelection,
getTypeaheadRegexMatches,
useUserMentionsCandidates,
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
@@ -41,7 +41,7 @@
import { useEditMessage } from 'lib/shared/edit-messages-utils.js';
import {
useMentionTypeaheadUserSuggestions,
- getMentionTypeaheadChatSuggestions,
+ useMentionTypeaheadChatSuggestions,
getTypeaheadRegexMatches,
type Selection,
useUserMentionsCandidates,
@@ -1316,26 +1316,17 @@
typeaheadMatchedStrings,
);
- const suggestions: $ReadOnlyArray<MentionTypeaheadSuggestionItem> =
- React.useMemo(() => {
- if (!typeaheadRegexMatches || !typeaheadMatchedStrings) {
- return [];
- }
-
- const suggestedChats = getMentionTypeaheadChatSuggestions(
- chatMentionSearchIndex,
- chatMentionCandidates,
- typeaheadMatchedStrings.query,
- );
+ const suggestedChats = useMentionTypeaheadChatSuggestions(
+ chatMentionSearchIndex,
+ chatMentionCandidates,
+ typeaheadMatchedStrings,
+ );
- return [...suggestedUsers, ...suggestedChats];
- }, [
- chatMentionCandidates,
- chatMentionSearchIndex,
- typeaheadRegexMatches,
- typeaheadMatchedStrings,
- suggestedUsers,
- ]);
+ const suggestions: $ReadOnlyArray<MentionTypeaheadSuggestionItem> =
+ React.useMemo(
+ () => [...suggestedUsers, ...suggestedChats],
+ [suggestedUsers, suggestedChats],
+ );
return (
<ChatInputBar
diff --git a/web/chat/chat-input-bar.react.js b/web/chat/chat-input-bar.react.js
--- a/web/chat/chat-input-bar.react.js
+++ b/web/chat/chat-input-bar.react.js
@@ -19,7 +19,7 @@
import {
getTypeaheadRegexMatches,
useUserMentionsCandidates,
- getMentionTypeaheadChatSuggestions,
+ useMentionTypeaheadChatSuggestions,
type MentionTypeaheadSuggestionItem,
type TypeaheadMatchedStrings,
useMentionTypeaheadUserSuggestions,
@@ -647,25 +647,17 @@
typeaheadMatchedStrings,
);
- const suggestions = React.useMemo(() => {
- if (!typeaheadMatchedStrings) {
- return ([]: $ReadOnlyArray<MentionTypeaheadSuggestionItem>);
- }
- const suggestedChats = getMentionTypeaheadChatSuggestions(
- chatMentionSearchIndex,
- props.inputState.typeaheadState.frozenChatMentionsCandidates,
- typeaheadMatchedStrings.query,
- );
- return ([
- ...suggestedUsers,
- ...suggestedChats,
- ]: $ReadOnlyArray<MentionTypeaheadSuggestionItem>);
- }, [
- suggestedUsers,
- typeaheadMatchedStrings,
- props.inputState.typeaheadState.frozenChatMentionsCandidates,
+ const suggestedChats = useMentionTypeaheadChatSuggestions(
chatMentionSearchIndex,
- ]);
+ props.inputState.typeaheadState.frozenChatMentionsCandidates,
+ typeaheadMatchedStrings,
+ );
+
+ const suggestions: $ReadOnlyArray<MentionTypeaheadSuggestionItem> =
+ React.useMemo(
+ () => [...suggestedUsers, ...suggestedChats],
+ [suggestedUsers, suggestedChats],
+ );
return (
<ChatInputBar

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 7, 10:09 PM (13 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5846140
Default Alt Text
D10432.1765145390.diff (4 KB)

Event Timeline