Page MenuHomePhabricator

D13533.id.diff
No OneTemporary

D13533.id.diff

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

Mime Type
text/plain
Expires
Wed, Oct 2, 11:06 AM (15 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2213806
Default Alt Text
D13533.id.diff (3 KB)

Event Timeline