Chore: Migrate REST API - searchMessages to Typescript (#3874)
This commit is contained in:
parent
69cf9b638e
commit
b5f8f6f305
|
@ -98,6 +98,7 @@ export interface IMessageFromServer {
|
|||
_id: string;
|
||||
username: string;
|
||||
};
|
||||
score?: number;
|
||||
}
|
||||
|
||||
export interface ILoadMoreMessage {
|
||||
|
|
|
@ -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[];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue