Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3530012
D8833.id29950.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D8833.id29950.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
@@ -77,6 +77,9 @@
type ClientNewThreadRequest,
type NewThreadResult,
type ChangeThreadSettingsPayload,
+ type ResolvedThreadInfo,
+ type ChatMentionCandidatesObj,
+ type ChatMentionCandidates,
} from '../types/thread-types.js';
import { updateTypes } from '../types/update-types-enum.js';
import { type ClientUpdateInfo } from '../types/update-types.js';
@@ -92,6 +95,7 @@
} from '../utils/action-utils.js';
import type { DispatchActionPromise } from '../utils/action-utils.js';
import type { GetENSNames } from '../utils/ens-helpers.js';
+import { useResolvedThreadInfosObj } from '../utils/entity-helpers.js';
import {
ET,
entityTextToRawString,
@@ -1621,6 +1625,96 @@
} within this ${communityOrThreadNoun(threadInfo)}`;
}
+function getChatMentionCandidates(threadInfos: {
+ +[id: string]: ResolvedThreadInfo,
+}): ChatMentionCandidatesObj {
+ const result = {};
+ const visitedGenesisCommunityThreads = new Set();
+ for (const currentThreadID in threadInfos) {
+ const currentThreadInfo = threadInfos[currentThreadID];
+ const { community: currentThreadCommunity } = currentThreadInfo;
+ if (!currentThreadCommunity) {
+ result[currentThreadID] = [currentThreadInfo];
+ continue;
+ }
+ // Handle GENESIS community case: mentioning inside GENESIS should only
+ // show chats and threads inside the top level that is below GENESIS.
+ if (threadInfos[currentThreadCommunity].type === threadTypes.GENESIS) {
+ if (visitedGenesisCommunityThreads.has(currentThreadID)) {
+ continue;
+ }
+ const threadTraversePath = [currentThreadInfo];
+ visitedGenesisCommunityThreads.add(currentThreadID);
+ let currentlySelectedThreadID = currentThreadInfo.parentThreadID;
+ while (currentlySelectedThreadID) {
+ const currentlySelectedThreadInfo =
+ threadInfos[currentlySelectedThreadID];
+ if (
+ visitedGenesisCommunityThreads.has(currentlySelectedThreadID) ||
+ currentlySelectedThreadInfo.type === threadTypes.GENESIS
+ ) {
+ break;
+ }
+ threadTraversePath.push(currentlySelectedThreadInfo);
+ visitedGenesisCommunityThreads.add(currentlySelectedThreadID);
+ currentlySelectedThreadID = currentlySelectedThreadInfo.parentThreadID;
+ }
+ const lastThreadInTraversePath =
+ threadTraversePath[threadTraversePath.length - 1];
+ const lastThreadInTraversePathID =
+ lastThreadInTraversePath.parentThreadID ?? lastThreadInTraversePath.id;
+ if (
+ threadInfos[lastThreadInTraversePathID].type === threadTypes.GENESIS
+ ) {
+ const threadObjectFromTraversePath = {};
+ for (const threadInfo of threadTraversePath) {
+ threadObjectFromTraversePath[threadInfo.id] = threadInfo;
+ result[threadInfo.id] = threadObjectFromTraversePath;
+ }
+ } else {
+ for (const threadInfo of threadTraversePath) {
+ result[lastThreadInTraversePathID][threadInfo.id] = threadInfo;
+ result[threadInfo.id] = result[lastThreadInTraversePathID];
+ }
+ }
+ continue;
+ }
+ result[currentThreadCommunity][currentThreadID] = currentThreadInfo;
+ result[currentThreadID] = result[currentThreadCommunity];
+ }
+ return result;
+}
+
+function useChatMentionCandidatesObj(): ChatMentionCandidatesObj {
+ const threadInfos = useSelector(threadInfoSelector);
+ const resolvedThreadInfos = useResolvedThreadInfosObj(threadInfos);
+ return React.useMemo(
+ () => getChatMentionCandidates(resolvedThreadInfos),
+ [resolvedThreadInfos],
+ );
+}
+
+function threadChatMentionCandidates(
+ threadInfo: ThreadInfo,
+ chatMentionCandidates: ChatMentionCandidatesObj,
+): ChatMentionCandidates {
+ return (
+ chatMentionCandidates[threadInfo.id] ??
+ (threadInfo.containingThreadID &&
+ chatMentionCandidates[threadInfo.containingThreadID])
+ );
+}
+
+function useThreadChatMentionCandidates(
+ threadInfo: ThreadInfo,
+): ChatMentionCandidates {
+ const chatMentionCandidates = useChatMentionCandidatesObj();
+ return React.useMemo(
+ () => threadChatMentionCandidates(threadInfo, chatMentionCandidates),
+ [chatMentionCandidates, threadInfo],
+ );
+}
+
export {
threadHasPermission,
viewerIsMember,
@@ -1689,4 +1783,7 @@
useRoleMemberCountsForCommunity,
useRoleUserSurfacedPermissions,
getThreadsToDeleteText,
+ useChatMentionCandidatesObj,
+ threadChatMentionCandidates,
+ useThreadChatMentionCandidates,
};
diff --git a/lib/types/thread-types.js b/lib/types/thread-types.js
--- a/lib/types/thread-types.js
+++ b/lib/types/thread-types.js
@@ -456,3 +456,8 @@
export const maxUnreadSidebars = 5;
export type ThreadStoreThreadInfos = { +[id: string]: RawThreadInfo };
+
+export type ChatMentionCandidates = { +[id: string]: ResolvedThreadInfo };
+export type ChatMentionCandidatesObj = {
+ +[id: string]: ChatMentionCandidates,
+};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Dec 25, 10:51 PM (12 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2703363
Default Alt Text
D8833.id29950.diff (4 KB)
Attached To
Mode
D8833: [lib] Introduce chat mention candidates getters
Attached
Detach File
Event Timeline
Log In to Comment