Page MenuHomePhabricator

D13831.id45544.diff
No OneTemporary

D13831.id45544.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
@@ -4,11 +4,15 @@
import { useGetLatestMessageEdit } from './latest-message-edit.js';
import { messageInfoSelector } from '../selectors/chat-selectors.js';
-import { getOldestNonLocalMessageID } from '../shared/message-utils.js';
+import {
+ getOldestNonLocalMessageID,
+ useFetchMessages,
+} from '../shared/message-utils.js';
import { messageSpecs } from '../shared/messages/message-specs.js';
import type { MessageInfo } from '../types/message-types.js';
import type { ThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js';
import { useSelector } from '../utils/redux-utils.js';
+import sleep from '../utils/sleep.js';
function useOldestMessageServerID(threadID: string): ?string {
return useSelector(state =>
@@ -102,6 +106,24 @@
})();
}, [threadInfo, getMessageInfoForPreview]);
+ const shouldFetchOlderMessages =
+ !!messageInfoForPreview?.shouldFetchOlderMessages;
+
+ const [canFetchOlderMessages, setCanFetchOlderMessages] =
+ React.useState(true);
+ const fetchMessages = useFetchMessages(threadInfo);
+ React.useEffect(() => {
+ if (!canFetchOlderMessages || !shouldFetchOlderMessages) {
+ return;
+ }
+ setCanFetchOlderMessages(false);
+ void (async () => {
+ await fetchMessages();
+ await sleep(3000);
+ setCanFetchOlderMessages(true);
+ })();
+ }, [canFetchOlderMessages, shouldFetchOlderMessages, fetchMessages]);
+
return messageInfoForPreview?.messageInfoForPreview;
}

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 3, 2:01 AM (19 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2609744
Default Alt Text
D13831.id45544.diff (1 KB)

Event Timeline