Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3352598
D13830.id45480.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
D13830.id45480.diff
View Options
diff --git a/lib/hooks/message-hooks.js b/lib/hooks/message-hooks.js
--- a/lib/hooks/message-hooks.js
+++ b/lib/hooks/message-hooks.js
@@ -16,9 +16,23 @@
);
}
+type MessageInfoForPreview = {
+ +messageInfoForPreview: ?MessageInfo,
+ // If showInMessagePreview rejects all of the messages in the local store,
+ // then we'll ignore it and return the most recent message (if there is one)
+ // as messageInfoForPreview. In this case, we'll also set
+ // shouldFetchOlderMessages to tell the caller to fetch more messages.
+ +shouldFetchOlderMessages: boolean,
+};
+
+const emptyMessageInfoForPreview = {
+ messageInfoForPreview: undefined,
+ shouldFetchOlderMessages: false,
+};
+
function useGetMessageInfoForPreview(): (
threadInfo: ThreadInfo,
-) => Promise<?MessageInfo> {
+) => Promise<MessageInfoForPreview> {
const messageInfos = useSelector(messageInfoSelector);
const messageStore = useSelector(state => state.messageStore);
const viewerID = useSelector(state => state.currentUserInfo?.id);
@@ -26,11 +40,11 @@
return React.useCallback(
async threadInfo => {
if (!viewerID) {
- return null;
+ return emptyMessageInfoForPreview;
}
const thread = messageStore.threads[threadInfo.id];
if (!thread) {
- return null;
+ return emptyMessageInfoForPreview;
}
const showInMessagePreviewParams = {
threadInfo,
@@ -44,35 +58,56 @@
}
const { showInMessagePreview } = messageSpecs[messageInfo.type];
if (!showInMessagePreview) {
- return messageInfo;
+ return {
+ messageInfoForPreview: messageInfo,
+ shouldFetchOlderMessages: false,
+ };
}
const shouldShow = await showInMessagePreview(
messageInfo,
showInMessagePreviewParams,
);
if (shouldShow) {
- return messageInfo;
+ return {
+ messageInfoForPreview: messageInfo,
+ shouldFetchOlderMessages: false,
+ };
}
}
- return null;
+ // If we get here, that means showInMessagePreview rejected all of the
+ // messages in the local store
+ for (const messageID of thread.messageIDs) {
+ const messageInfo = messageInfos[messageID];
+ if (messageInfo) {
+ return {
+ messageInfoForPreview: messageInfo,
+ shouldFetchOlderMessages: true,
+ };
+ }
+ }
+ return {
+ messageInfoForPreview: undefined,
+ shouldFetchOlderMessages: true,
+ };
},
[messageInfos, messageStore, viewerID, fetchMessage],
);
}
function useMessageInfoForPreview(threadInfo: ThreadInfo): ?MessageInfo {
- const [messageInfo, setMessageInfo] = React.useState<?MessageInfo>();
+ const [messageInfoForPreview, setMessageInfoForPreview] =
+ React.useState<?MessageInfoForPreview>();
const getMessageInfoForPreview = useGetMessageInfoForPreview();
React.useEffect(() => {
void (async () => {
const newMessageInfoForPreview =
await getMessageInfoForPreview(threadInfo);
- setMessageInfo(newMessageInfoForPreview);
+ setMessageInfoForPreview(newMessageInfoForPreview);
})();
}, [threadInfo, getMessageInfoForPreview]);
- return messageInfo;
+ return messageInfoForPreview?.messageInfoForPreview;
}
export { useOldestMessageServerID, useMessageInfoForPreview };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 6:32 AM (12 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2574309
Default Alt Text
D13830.id45480.diff (3 KB)
Attached To
Mode
D13830: [lib][native][web] Ignore showInMessagePreview if no messages found
Attached
Detach File
Event Timeline
Log In to Comment