Page MenuHomePhabricator

D13830.id45480.diff
No OneTemporary

D13830.id45480.diff

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

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)

Event Timeline