Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3344124
D13162.id43664.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D13162.id43664.diff
View Options
diff --git a/lib/actions/message-actions.js b/lib/actions/message-actions.js
--- a/lib/actions/message-actions.js
+++ b/lib/actions/message-actions.js
@@ -29,7 +29,10 @@
RawMessageInfo,
MessageTruncationStatuses,
} from '../types/message-types.js';
-import { defaultNumberPerThread } from '../types/message-types.js';
+import {
+ defaultNumberPerThread,
+ messageTruncationStatus,
+} from '../types/message-types.js';
import type { MediaMessageServerDBContent } from '../types/messages/media.js';
import type { ThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js';
import { threadTypeIsThick } from '../types/thread-types-enum.js';
@@ -40,6 +43,7 @@
import { getConfig } from '../utils/config.js';
import { translateClientDBMessageInfoToRawMessageInfo } from '../utils/message-ops-utils.js';
import { useDispatchActionPromise } from '../utils/redux-promise-utils.js';
+import { useSelector } from '../utils/redux-utils.js';
const fetchMessagesBeforeCursorActionTypes = Object.freeze({
started: 'FETCH_MESSAGES_BEFORE_CURSOR_STARTED',
@@ -545,6 +549,29 @@
return useKeyserverCall(toggleMessagePin);
}
+async function fetchThickThreadMessages(
+ threadID: string,
+ limit: number,
+ offset: number,
+): Promise<FetchMessageInfosPayload> {
+ const { sqliteAPI } = getConfig();
+ const dbMessages = await sqliteAPI.fetchMessages(threadID, limit + 1, offset);
+ const isFetchExhaustive = dbMessages.length !== limit + 1;
+ const messagesToReturn = isFetchExhaustive
+ ? dbMessages
+ : dbMessages.slice(0, -1);
+ const messages = messagesToReturn.map(
+ translateClientDBMessageInfoToRawMessageInfo,
+ );
+ return {
+ threadID,
+ rawMessageInfos: messages,
+ truncationStatus: isFetchExhaustive
+ ? messageTruncationStatus.EXHAUSTIVE
+ : messageTruncationStatus.UNCHANGED,
+ };
+}
+
function useFetchMessages(threadInfo: ThreadInfo): () => Promise<void> {
const oldestMessageServerID = useOldestMessageServerID(threadInfo.id);
const callFetchMessagesBeforeCursor = useFetchMessagesBeforeCursor();
@@ -556,9 +583,31 @@
registerFetchKey(fetchMostRecentMessagesActionTypes);
}, []);
+ const threadID = threadInfo.id;
+ const messageIDs = useSelector(
+ state => state.messageStore.threads[threadID].messageIDs,
+ );
+ const numberOfFetchedMessages = React.useRef(messageIDs?.length ?? 0);
+
+ React.useEffect(() => {
+ numberOfFetchedMessages.current = 0;
+ }, [threadInfo.id]);
+
return React.useCallback(async () => {
- const threadID = threadInfo.id;
if (threadTypeIsThick(threadInfo.type)) {
+ const promise = (async () => {
+ const fetchResult = await fetchThickThreadMessages(
+ threadID,
+ defaultNumberPerThread,
+ numberOfFetchedMessages.current,
+ );
+ numberOfFetchedMessages.current += fetchResult.rawMessageInfos.length;
+ return fetchResult;
+ })();
+ await dispatchActionPromise(
+ fetchMessagesBeforeCursorActionTypes,
+ promise,
+ );
return;
}
if (oldestMessageServerID) {
@@ -580,7 +629,7 @@
callFetchMostRecentMessages,
dispatchActionPromise,
oldestMessageServerID,
- threadInfo.id,
+ threadID,
threadInfo.type,
]);
}
diff --git a/lib/reducers/message-reducer.js b/lib/reducers/message-reducer.js
--- a/lib/reducers/message-reducer.js
+++ b/lib/reducers/message-reducer.js
@@ -606,6 +606,26 @@
updatedThreads[threadID] = threads[threadID];
}
+ const dbOps = [
+ ...newMessageOps,
+ {
+ type: 'replace_threads',
+ payload: {
+ threads: Object.fromEntries(
+ Object.entries(updatedThreads).map(([threadID, thread]) => [
+ threadID,
+ threadInfos[threadID].thick
+ ? {
+ ...thread,
+ startReached:
+ thread.messageIDs.length < defaultNumberPerThread,
+ }
+ : thread,
+ ]),
+ ),
+ },
+ },
+ ];
newMessageOps.push({
type: 'replace_threads',
payload: {
@@ -640,10 +660,7 @@
};
return {
- messageStoreOperations: [
- ...updateWithLatestThreadInfosOps,
- ...newMessageOps,
- ],
+ messageStoreOperations: [...updateWithLatestThreadInfosOps, ...dbOps],
messageStore,
};
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 23, 4:19 AM (17 h, 6 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2568261
Default Alt Text
D13162.id43664.diff (4 KB)
Attached To
Mode
D13162: [lib] Fetch thick thread messages
Attached
Detach File
Event Timeline
Log In to Comment