From b5f8f6f305afd9db6837ecbdc55e1c13af550c0c Mon Sep 17 00:00:00 2001 From: Alex Junior Date: Thu, 10 Mar 2022 12:17:49 -0300 Subject: [PATCH] Chore: Migrate REST API - searchMessages to Typescript (#3874) --- app/definitions/IMessage.ts | 1 + app/definitions/rest/v1/chat.ts | 5 +++++ app/lib/rocketchat/services/restApi.ts | 4 +--- app/views/SearchMessagesView/index.tsx | 4 +++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/definitions/IMessage.ts b/app/definitions/IMessage.ts index 538d4d25..aa4a293e 100644 --- a/app/definitions/IMessage.ts +++ b/app/definitions/IMessage.ts @@ -98,6 +98,7 @@ export interface IMessageFromServer { _id: string; username: string; }; + score?: number; } export interface ILoadMoreMessage { diff --git a/app/definitions/rest/v1/chat.ts b/app/definitions/rest/v1/chat.ts index 417d54a2..07edd43e 100644 --- a/app/definitions/rest/v1/chat.ts +++ b/app/definitions/rest/v1/chat.ts @@ -60,4 +60,9 @@ export type ChatEndpoints = { 'chat.ignoreUser': { GET: (params: { rid: string; userId: string; ignore: boolean }) => {}; }; + 'chat.search': { + GET: (params: { roomId: IServerRoom['_id']; searchText: string; count: number; offset: number }) => { + messages: IMessageFromServer[]; + }; + }; }; diff --git a/app/lib/rocketchat/services/restApi.ts b/app/lib/rocketchat/services/restApi.ts index efe25d39..9d486d7e 100644 --- a/app/lib/rocketchat/services/restApi.ts +++ b/app/lib/rocketchat/services/restApi.ts @@ -624,10 +624,8 @@ export const getReadReceipts = (messageId: string): any => messageId }); -export const searchMessages = (roomId: string, searchText: string, count: number, offset: number): any => +export const searchMessages = (roomId: string, searchText: string, count: number, offset: number) => // RC 0.60.0 - // TODO: missing definitions from server - // @ts-ignore sdk.get('chat.search', { roomId, searchText, diff --git a/app/views/SearchMessagesView/index.tsx b/app/views/SearchMessagesView/index.tsx index 417b240c..c2a48367 100644 --- a/app/views/SearchMessagesView/index.tsx +++ b/app/views/SearchMessagesView/index.tsx @@ -157,11 +157,13 @@ class SearchMessagesView extends React.Component { try { const messages = await this.searchMessages(searchText); + // @ts-ignore TODO: find a way to deal with the difference between IMessageFromServer and TMessageModel expected by state this.setState(prevState => ({ messages: debounced ? messages : [...prevState.messages, ...messages], loading: false