Chore: Migrate REST API - searchMessages to Typescript (#3874)

This commit is contained in:
Alex Junior 2022-03-10 12:17:49 -03:00 committed by GitHub
parent 69cf9b638e
commit b5f8f6f305
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 4 deletions

View File

@ -98,6 +98,7 @@ export interface IMessageFromServer {
_id: string;
username: string;
};
score?: number;
}
export interface ILoadMoreMessage {

View File

@ -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[];
};
};
};

View File

@ -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,

View File

@ -157,11 +157,13 @@ class SearchMessagesView extends React.Component<ISearchMessagesViewProps, ISear
if (result.success) {
return result.messages;
}
};
return [];
};
getMessages = async (searchText: string, debounced?: boolean) => {
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