Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32386284
D3566.1765333494.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D3566.1765333494.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
@@ -5,6 +5,7 @@
import type {
FetchMessageInfosPayload,
SendMessageResult,
+ SimpleMessagesPayload,
} from '../types/message-types';
import type { FetchJSON, FetchResultInfo } from '../utils/fetch-json';
@@ -56,6 +57,29 @@
};
};
+const fetchSingleMostRecentMessagesFromThreadsActionTypes = Object.freeze({
+ started: 'FETCH_SINGLE_MOST_RECENT_MESSAGES_FROM_THREADS_STARTED',
+ success: 'FETCH_SINGLE_MOST_RECENT_MESSAGES_FROM_THREADS_SUCCESS',
+ failed: 'FETCH_SINGLE_MOST_RECENT_MESSAGES_FROM_THREADS_FAILED',
+});
+const fetchSingleMostRecentMessagesFromThreads = (
+ fetchJSON: FetchJSON,
+): ((
+ threadIDs: $ReadOnlyArray<string>,
+) => Promise<SimpleMessagesPayload>) => async threadIDs => {
+ const cursors = Object.fromEntries(
+ threadIDs.map(threadID => [threadID, null]),
+ );
+ const response = await fetchJSON('fetch_messages', {
+ cursors,
+ numberPerThread: 1,
+ });
+ return {
+ rawMessageInfos: response.rawMessageInfos,
+ truncationStatuses: response.truncationStatuses,
+ };
+};
+
const sendTextMessageActionTypes = Object.freeze({
started: 'SEND_TEXT_MESSAGE_STARTED',
success: 'SEND_TEXT_MESSAGE_SUCCESS',
@@ -142,6 +166,8 @@
fetchMessagesBeforeCursor,
fetchMostRecentMessagesActionTypes,
fetchMostRecentMessages,
+ fetchSingleMostRecentMessagesFromThreadsActionTypes,
+ fetchSingleMostRecentMessagesFromThreads,
sendTextMessageActionTypes,
sendTextMessage,
createLocalMessageActionType,
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
@@ -29,6 +29,7 @@
processMessagesActionType,
messageStorePruneActionType,
createLocalMessageActionType,
+ fetchSingleMostRecentMessagesFromThreadsActionTypes,
setMessageStoreMessages,
} from '../actions/message-actions';
import {
@@ -807,6 +808,20 @@
action.type,
);
return { messageStoreOperations, messageStore: mergedMessageStore };
+ } else if (
+ action.type === fetchSingleMostRecentMessagesFromThreadsActionTypes.success
+ ) {
+ const {
+ messageStoreOperations,
+ messageStore: mergedMessageStore,
+ } = mergeNewMessages(
+ messageStore,
+ action.payload.rawMessageInfos,
+ action.payload.truncationStatuses,
+ newThreadInfos,
+ action.type,
+ );
+ return { messageStoreOperations, messageStore: mergedMessageStore };
} else if (
action.type === fetchMessagesBeforeCursorActionTypes.success ||
action.type === fetchMostRecentMessagesActionTypes.success
diff --git a/lib/types/message-types.js b/lib/types/message-types.js
--- a/lib/types/message-types.js
+++ b/lib/types/message-types.js
@@ -467,6 +467,10 @@
+truncationStatuses: MessageTruncationStatuses,
+currentAsOf: number,
};
+export type SimpleMessagesPayload = {
+ +rawMessageInfos: $ReadOnlyArray<RawMessageInfo>,
+ +truncationStatuses: MessageTruncationStatuses,
+};
export const defaultNumberPerThread = 20;
export const defaultMaxMessageAge = 14 * 24 * 60 * 60 * 1000; // 2 weeks
diff --git a/lib/types/redux-types.js b/lib/types/redux-types.js
--- a/lib/types/redux-types.js
+++ b/lib/types/redux-types.js
@@ -43,6 +43,7 @@
MessageStorePrunePayload,
LocallyComposedMessageInfo,
ClientDBMessageInfo,
+ SimpleMessagesPayload,
} from './message-types';
import type { RawTextMessageInfo } from './messages/text';
import type { BaseNavInfo } from './nav-types';
@@ -464,6 +465,22 @@
+payload: FetchMessageInfosPayload,
+loadingInfo: LoadingInfo,
}
+ | {
+ +type: 'FETCH_SINGLE_MOST_RECENT_MESSAGES_FROM_THREADS_STARTED',
+ +payload?: void,
+ +loadingInfo: LoadingInfo,
+ }
+ | {
+ +type: 'FETCH_SINGLE_MOST_RECENT_MESSAGES_FROM_THREADS_FAILED',
+ +error: true,
+ +payload: Error,
+ +loadingInfo: LoadingInfo,
+ }
+ | {
+ +type: 'FETCH_SINGLE_MOST_RECENT_MESSAGES_FROM_THREADS_SUCCESS',
+ +payload: SimpleMessagesPayload,
+ +loadingInfo: LoadingInfo,
+ }
| {
+type: 'SEND_TEXT_MESSAGE_STARTED',
+loadingInfo?: LoadingInfo,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Dec 10, 2:24 AM (21 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5859999
Default Alt Text
D3566.1765333494.diff (4 KB)
Attached To
Mode
D3566: [lib] New action to fetch single message for a list of threads
Attached
Detach File
Event Timeline
Log In to Comment