diff --git a/lib/shared/message-utils.js b/lib/shared/message-utils.js --- a/lib/shared/message-utils.js +++ b/lib/shared/message-utils.js @@ -592,13 +592,13 @@ return timePerKeyserver; } -export type FetchThickMessagesType = ( +export type FetchMessagesFromDBType = ( threadID: string, limit: number, offset: number, ) => Promise; -const fetchThickThreadMessages: FetchThickMessagesType = async ( +const fetchMessagesFromDB: FetchMessagesFromDBType = async ( threadID: string, limit: number, offset: number, @@ -654,7 +654,7 @@ oldestMessageServerID, }, { - fetchThickThreadMessages, + fetchMessagesFromDB, keyserverFetchMessagesBeforeCursor: callFetchMessagesBeforeCursor, keyserverFetchMostRecentMessages: callFetchMostRecentMessages, dispatchActionPromise, diff --git a/lib/shared/threads/protocols/dm-thread-protocol.js b/lib/shared/threads/protocols/dm-thread-protocol.js --- a/lib/shared/threads/protocols/dm-thread-protocol.js +++ b/lib/shared/threads/protocols/dm-thread-protocol.js @@ -681,7 +681,7 @@ const { threadID, numMessagesToFetch, currentNumberOfFetchedMessages } = input; const promise = (async () => { - return await utils.fetchThickThreadMessages( + return await utils.fetchMessagesFromDB( threadID, numMessagesToFetch ?? defaultNumberPerThread, currentNumberOfFetchedMessages, diff --git a/lib/shared/threads/protocols/farcaster-thread-protocol.js b/lib/shared/threads/protocols/farcaster-thread-protocol.js --- a/lib/shared/threads/protocols/farcaster-thread-protocol.js +++ b/lib/shared/threads/protocols/farcaster-thread-protocol.js @@ -2,6 +2,7 @@ import invariant from 'invariant'; +import { fetchMessagesBeforeCursorActionTypes } from '../../../actions/message-actions.js'; import { getFarcasterRolePermissionsBlobs } from '../../../permissions/farcaster-permissions.js'; import type { RolePermissionBlobs } from '../../../permissions/thread-permissions.js'; import type { SetThreadUnreadStatusPayload } from '../../../types/activity-types.js'; @@ -11,6 +12,7 @@ SaveEntryResult, } from '../../../types/entry-types.js'; import { + defaultNumberPerThread, type SendMessagePayload, type SendMultimediaMessagePayload, } from '../../../types/message-types.js'; @@ -38,6 +40,8 @@ import { messageNotifyTypes } from '../../messages/message-spec.js'; import { getSingleOtherUser } from '../../thread-utils.js'; import type { + FetchMessageUtils, + ProtocolFetchMessageInput, ProtocolSendTextMessageInput, SendTextMessageUtils, ThreadProtocol, @@ -178,8 +182,24 @@ return rawThreadInfo; }, - fetchMessages: async (): Promise => { - throw new Error('fetchMessages method is not yet implemented'); + fetchMessages: async ( + input: ProtocolFetchMessageInput, + utils: FetchMessageUtils, + ) => { + const { threadID, numMessagesToFetch, currentNumberOfFetchedMessages } = + input; + const promise = (async () => { + return await utils.fetchMessagesFromDB( + threadID, + numMessagesToFetch ?? defaultNumberPerThread, + currentNumberOfFetchedMessages, + ); + })(); + void utils.dispatchActionPromise( + fetchMessagesBeforeCursorActionTypes, + promise, + ); + await promise; }, createPendingThread: (): RawThreadInfo => { diff --git a/lib/shared/threads/thread-spec.js b/lib/shared/threads/thread-spec.js --- a/lib/shared/threads/thread-spec.js +++ b/lib/shared/threads/thread-spec.js @@ -88,7 +88,7 @@ SendFarcasterMessageResult, SendFarcasterTextMessageInput, } from '../farcaster/farcaster-api.js'; -import type { FetchThickMessagesType } from '../message-utils.js'; +import type { FetchMessagesFromDBType } from '../message-utils.js'; import type { CreationSideEffectsFunc, MessageNotifyType, @@ -244,7 +244,7 @@ +oldestMessageServerID: ?string, }; export type FetchMessageUtils = { - +fetchThickThreadMessages: FetchThickMessagesType, + +fetchMessagesFromDB: FetchMessagesFromDBType, +keyserverFetchMessagesBeforeCursor: FetchMessagesBeforeCursorInput => Promise, +keyserverFetchMostRecentMessages: FetchMostRecentMessagesInput => Promise, +dispatchActionPromise: DispatchActionPromise,