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;
|
_id: string;
|
||||||
username: string;
|
username: string;
|
||||||
};
|
};
|
||||||
|
score?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ILoadMoreMessage {
|
export interface ILoadMoreMessage {
|
||||||
|
|
|
@ -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[];
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue