Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3311469
D13533.id44763.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D13533.id44763.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
@@ -1676,6 +1676,14 @@
} within this ${communityOrThreadNoun(threadInfo)}`;
}
+type OldestCreatedInput = { +creationTime: number, ... };
+function getOldestCreated<T: OldestCreatedInput>(arr: $ReadOnlyArray<T>): ?T {
+ return arr.reduce<?T>(
+ (a, b) => (!b || (a && a.creationTime < b.creationTime) ? a : b),
+ null,
+ );
+}
+
function useUserProfileThreadInfo(userInfo: ?UserInfo): ?UserProfileThreadInfo {
const userID = userInfo?.id;
const username = userInfo?.username;
@@ -1683,18 +1691,37 @@
const loggedInUserInfo = useLoggedInUserInfo();
const isViewerProfile = loggedInUserInfo?.id === userID;
- const privateThreadInfosSelector = threadInfosSelectorForThreadType(
+ const genesisPrivateThreadInfosSelector = threadInfosSelectorForThreadType(
threadTypes.GENESIS_PRIVATE,
);
+ const genesisPrivateThreadInfos = useSelector(
+ genesisPrivateThreadInfosSelector,
+ );
+ const privateThreadInfosSelector = threadInfosSelectorForThreadType(
+ threadTypes.PRIVATE,
+ );
const privateThreadInfos = useSelector(privateThreadInfosSelector);
+ const oldestPrivateThreadInfo = React.useMemo(
+ () =>
+ getOldestCreated([...privateThreadInfos, ...genesisPrivateThreadInfos]),
+ [privateThreadInfos, genesisPrivateThreadInfos],
+ );
- const personalThreadInfosSelector = threadInfosSelectorForThreadType(
+ const usersWithPersonalThread = useSelector(usersWithPersonalThreadSelector);
+ const genesisPersonalThreadInfosSelector = threadInfosSelectorForThreadType(
threadTypes.GENESIS_PERSONAL,
);
-
+ const genesisPersonalThreadInfos = useSelector(
+ genesisPersonalThreadInfosSelector,
+ );
+ const personalThreadInfosSelector = threadInfosSelectorForThreadType(
+ threadTypes.PERSONAL,
+ );
const personalThreadInfos = useSelector(personalThreadInfosSelector);
-
- const usersWithPersonalThread = useSelector(usersWithPersonalThreadSelector);
+ const allPersonalThreadInfos = React.useMemo(
+ () => [...personalThreadInfos, ...genesisPersonalThreadInfos],
+ [personalThreadInfos, genesisPersonalThreadInfos],
+ );
const [supportThickThreads, setSupportThickThreads] = React.useState(false);
const usersSupportThickThreads = useUsersSupportThickThreads();
@@ -1716,17 +1743,18 @@
}
if (isViewerProfile) {
- const privateThreadInfo: ?ThreadInfo = privateThreadInfos[0];
-
- return privateThreadInfo ? { threadInfo: privateThreadInfo } : null;
+ return oldestPrivateThreadInfo
+ ? { threadInfo: oldestPrivateThreadInfo }
+ : null;
}
if (usersWithPersonalThread.has(userID)) {
- const personalThreadInfo: ?ThreadInfo = personalThreadInfos.find(
- threadInfo =>
- userID === getSingleOtherUser(threadInfo, loggedInUserInfo.id),
+ const personalThreadInfo: ?ThreadInfo = getOldestCreated(
+ allPersonalThreadInfos.filter(
+ threadInfo =>
+ userID === getSingleOtherUser(threadInfo, loggedInUserInfo.id),
+ ),
);
-
return personalThreadInfo ? { threadInfo: personalThreadInfo } : null;
}
@@ -1741,8 +1769,8 @@
}, [
isViewerProfile,
loggedInUserInfo,
- personalThreadInfos,
- privateThreadInfos,
+ allPersonalThreadInfos,
+ oldestPrivateThreadInfo,
supportThickThreads,
userID,
username,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 20, 8:54 AM (18 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2543702
Default Alt Text
D13533.id44763.diff (3 KB)
Attached To
Mode
D13533: [lib] Update useUserProfileThreadInfo to consider thick threads
Attached
Detach File
Event Timeline
Log In to Comment