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 @@ -11,6 +11,8 @@ SendEditMessageRequest, FetchPinnedMessagesRequest, FetchPinnedMessagesResult, + SearchMessagesRequest, + SearchMessagesResult, } from '../types/message-types.js'; import type { MediaMessageServerDBContent } from '../types/messages/media.js'; import type { @@ -282,6 +284,23 @@ return { pinnedMessages: response.pinnedMessages }; }; +const searchMessagesActionTypes = Object.freeze({ + started: 'SEARCH_MESSAGES_STARTED', + success: 'SEARCH_MESSAGES_SUCCESS', + failed: 'SEARCH_MESSAGES_FAILED', +}); + +const searchMessages = + ( + callServerEndpoint: CallServerEndpoint, + ): ((request: SearchMessagesRequest) => Promise) => + async request => { + const response = await callServerEndpoint('search_messages', request); + return { + messages: response.messages, + }; + }; + export { fetchMessagesBeforeCursorActionTypes, fetchMessagesBeforeCursor, @@ -295,6 +314,8 @@ sendMultimediaMessageActionTypes, sendMultimediaMessage, legacySendMultimediaMessage, + searchMessagesActionTypes, + searchMessages, sendReactionMessageActionTypes, sendReactionMessage, saveMessagesActionType, 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 @@ -50,6 +50,7 @@ SimpleMessagesPayload, ClientDBThreadMessageInfo, FetchPinnedMessagesResult, + SearchMessagesResult, } from './message-types.js'; import type { RawReactionMessageInfo } from './messages/reaction.js'; import type { RawTextMessageInfo } from './messages/text.js'; @@ -988,6 +989,22 @@ +error: true, +payload: Error, +loadingInfo: LoadingInfo, + } + | { + +type: 'SEARCH_MESSAGES_STARTED', + +payload: void, + +loadingInfo?: LoadingInfo, + } + | { + +type: 'SEARCH_MESSAGES_SUCCESS', + +payload: SearchMessagesResult, + +loadingInfo: LoadingInfo, + } + | { + +type: 'SEARCH_MESSAGES_FAILED', + +error: true, + +payload: Error, + +loadingInfo: LoadingInfo, }; export type ActionPayload = ?(Object | Array<*> | $ReadOnlyArray<*> | string);