Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3339878
D9247.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D9247.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
@@ -38,6 +38,7 @@
import {
threadInfoSelector,
pendingToRealizedThreadIDsSelector,
+ threadInfosSelectorForThreadType,
} from '../selectors/thread-selectors.js';
import {
getRelativeMemberInfos,
@@ -80,6 +81,7 @@
type ResolvedThreadInfo,
type ChatMentionCandidatesObj,
type ChatMentionCandidates,
+ type UserProfileThreadInfo,
} from '../types/thread-types.js';
import { updateTypes } from '../types/update-types-enum.js';
import { type ClientUpdateInfo } from '../types/update-types.js';
@@ -1795,6 +1797,64 @@
]);
}
+function useUserProfileThreadInfo(userInfo: ?UserInfo): ?UserProfileThreadInfo {
+ const userID = userInfo?.id;
+ const username = userInfo?.username;
+
+ const loggedInUserInfo = useLoggedInUserInfo();
+ const isViewerProfile = loggedInUserInfo?.id === userID;
+
+ const privateThreadInfosSelector = threadInfosSelectorForThreadType(
+ threadTypes.PRIVATE,
+ );
+ const privateThreadInfos = useSelector(privateThreadInfosSelector);
+
+ const personalThreadInfosSelector = threadInfosSelectorForThreadType(
+ threadTypes.PERSONAL,
+ );
+
+ const personalThreadInfos = useSelector(personalThreadInfosSelector);
+
+ const usersWithPersonalThread = useSelector(usersWithPersonalThreadSelector);
+
+ return React.useMemo(() => {
+ if (!loggedInUserInfo || !userID || !username) {
+ return null;
+ }
+
+ if (isViewerProfile) {
+ const privateThreadInfo: ?ThreadInfo = privateThreadInfos[0];
+
+ return privateThreadInfo ? { threadInfo: privateThreadInfo } : null;
+ }
+
+ if (usersWithPersonalThread.has(userID)) {
+ const personalThreadInfo: ?ThreadInfo = personalThreadInfos.find(
+ threadInfo =>
+ userID === getSingleOtherUser(threadInfo, loggedInUserInfo.id),
+ );
+
+ return personalThreadInfo ? { threadInfo: personalThreadInfo } : null;
+ }
+
+ const pendingPersonalThreadInfo = createPendingPersonalThread(
+ loggedInUserInfo,
+ userID,
+ username,
+ );
+
+ return pendingPersonalThreadInfo;
+ }, [
+ isViewerProfile,
+ loggedInUserInfo,
+ personalThreadInfos,
+ privateThreadInfos,
+ userID,
+ username,
+ usersWithPersonalThread,
+ ]);
+}
+
export {
threadHasPermission,
viewerIsMember,
@@ -1864,4 +1924,5 @@
getThreadsToDeleteText,
useChatMentionCandidatesObj,
useThreadChatMentionCandidates,
+ useUserProfileThreadInfo,
};
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
@@ -464,3 +464,8 @@
export type ChatMentionCandidatesObj = {
+[id: string]: ChatMentionCandidates,
};
+
+export type UserProfileThreadInfo = {
+ +threadInfo: ThreadInfo,
+ +pendingPersonalThreadUserInfo?: UserInfo,
+};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 22, 9:01 PM (17 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2564880
Default Alt Text
D9247.diff (2 KB)
Attached To
Mode
D9247: [lib] introduce useUserProfileThreadInfo hook
Attached
Detach File
Event Timeline
Log In to Comment