diff --git a/keyserver/src/endpoints.js b/keyserver/src/endpoints.js --- a/keyserver/src/endpoints.js +++ b/keyserver/src/endpoints.js @@ -27,6 +27,7 @@ reactionMessageCreationResponder, editMessageCreationResponder, fetchPinnedMessagesResponder, + searchMessagesResponder, } from './responders/message-responders.js'; import { updateRelationshipsResponder } from './responders/relationship-responders.js'; import { @@ -250,6 +251,10 @@ responder: codeVerificationResponder, requiredPolicies: baseLegalPolicies, }, + search_messages: { + responder: searchMessagesResponder, + requiredPolicies: baseLegalPolicies, + }, siwe_nonce: { responder: siweNonceResponder, requiredPolicies: [], diff --git a/keyserver/src/responders/message-responders.js b/keyserver/src/responders/message-responders.js --- a/keyserver/src/responders/message-responders.js +++ b/keyserver/src/responders/message-responders.js @@ -23,6 +23,8 @@ type SendEditMessageResponse, type FetchPinnedMessagesRequest, type FetchPinnedMessagesResult, + type SearchMessagesResponse, + type SearchMessagesRequest, } from 'lib/types/message-types.js'; import type { EditMessageData } from 'lib/types/messages/edit.js'; import type { ReactionMessageData } from 'lib/types/messages/reaction.js'; @@ -44,6 +46,7 @@ fetchMessageInfoByID, fetchThreadMessagesCount, fetchPinnedMessageInfos, + searchMessagesInSingleChat, } from '../fetchers/message-fetchers.js'; import { fetchServerThreadInfos } from '../fetchers/thread-fetchers.js'; import { checkThreadPermission } from '../fetchers/thread-permission-fetchers.js'; @@ -401,6 +404,27 @@ return await fetchPinnedMessageInfos(viewer, request); } +const searchMessagesResponderInputValidator = tShape({ + query: t.String, + threadID: t.String, + cursor: t.maybe(t.String), +}); + +async function searchMessagesResponder( + viewer: Viewer, + input: any, +): Promise { + const request: SearchMessagesRequest = input; + await validateInput(viewer, searchMessagesResponderInputValidator, input); + const messages = await searchMessagesInSingleChat( + request.query, + request.threadID, + viewer, + request.cursor, + ); + return { messages }; +} + export { textMessageCreationResponder, messageFetchResponder, @@ -408,4 +432,5 @@ reactionMessageCreationResponder, editMessageCreationResponder, fetchPinnedMessagesResponder, + searchMessagesResponder, }; diff --git a/lib/types/endpoints.js b/lib/types/endpoints.js --- a/lib/types/endpoints.js +++ b/lib/types/endpoints.js @@ -87,6 +87,7 @@ SIWE_NONCE: 'siwe_nonce', SIWE_AUTH: 'siwe_auth', UPDATE_USER_AVATAR: 'update_user_avatar', + SEARCH_MESSAGES: 'search_messages', }); type SocketPreferredEndpoint = $Values; 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 @@ -683,3 +683,15 @@ export type FetchPinnedMessagesResult = { +pinnedMessages: $ReadOnlyArray, }; + +export type SearchMessagesRequest = { + +query: string, + +threadID: string, + +cursor?: string, +}; + +export type SearchMessagesResponse = { + +messages: $ReadOnlyArray, +}; + +export type SearchMessagesResult = SearchMessagesResponse;