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; _id: string;
username: string; username: string;
}; };
score?: number;
} }
export interface ILoadMoreMessage { export interface ILoadMoreMessage {

View File

@ -60,4 +60,9 @@ export type ChatEndpoints = {
'chat.ignoreUser': { 'chat.ignoreUser': {
GET: (params: { rid: string; userId: string; ignore: boolean }) => {}; 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 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 // RC 0.60.0
// TODO: missing definitions from server
// @ts-ignore
sdk.get('chat.search', { sdk.get('chat.search', {
roomId, roomId,
searchText, searchText,

View File

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