Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32279367
D8900.1765264361.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D8900.1765264361.diff
View Options
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
@@ -44,6 +44,7 @@
usersWithPersonalThreadSelector,
} from '../selectors/user-selectors.js';
import { getUserAvatarForThread } from '../shared/avatar-utils.js';
+import SentencePrefixSearchIndex from '../shared/sentence-prefix-search-index.js';
import type { CalendarQuery } from '../types/entry-types.js';
import { messageTypes } from '../types/message-types-enum.js';
import {
@@ -1795,6 +1796,50 @@
]);
}
+function useChatMentionSearchIndex(): {
+ +[id: string]: SentencePrefixSearchIndex,
+} {
+ const { chatMentionCandidatesObj } = useChatMentionCandidatesObjAndUtils();
+ return React.useMemo(() => {
+ const result = {};
+ for (const communityThreadID in chatMentionCandidatesObj) {
+ const searchIndex = new SentencePrefixSearchIndex();
+ result[communityThreadID] = searchIndex;
+ // Sort the keys so that the order of the search results is consistent
+ const threadIDs = Object.keys(
+ chatMentionCandidatesObj[communityThreadID],
+ ).sort((a, b) => {
+ const aName = chatMentionCandidatesObj[communityThreadID][a].uiName;
+ const bName = chatMentionCandidatesObj[communityThreadID][b].uiName;
+ return aName.localeCompare(bName);
+ });
+ for (const key of threadIDs) {
+ searchIndex.addEntry(
+ chatMentionCandidatesObj[communityThreadID][key].id,
+ chatMentionCandidatesObj[communityThreadID][key].uiName,
+ );
+ }
+ }
+ return result;
+ }, [chatMentionCandidatesObj]);
+}
+
+function useThreadChatMentionSearchIndex(
+ threadInfo: ThreadInfo,
+): SentencePrefixSearchIndex {
+ const chatMentionCandidatesSearchIndex = useChatMentionSearchIndex();
+ const { communityThreadIDForGenesisThreads } =
+ useChatMentionCandidatesObjAndUtils();
+ if (threadInfo.community === genesis.id) {
+ return chatMentionCandidatesSearchIndex[
+ communityThreadIDForGenesisThreads[threadInfo.id]
+ ];
+ }
+ return chatMentionCandidatesSearchIndex[
+ threadInfo.community ?? threadInfo.id
+ ];
+}
+
export {
threadHasPermission,
viewerIsMember,
@@ -1864,4 +1909,5 @@
getThreadsToDeleteText,
useChatMentionCandidatesObj,
useThreadChatMentionCandidates,
+ useThreadChatMentionSearchIndex,
};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 9, 7:12 AM (5 h, 8 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5853177
Default Alt Text
D8900.1765264361.diff (2 KB)
Attached To
Mode
D8900: [lib] Add chat mention SearchIndex selector
Attached
Detach File
Event Timeline
Log In to Comment