Chore: Migrate methods/loadNextMessages to typescript (#3719)
* feat: update loadNextMessages to ts * minor tweak * chore: minor tweaks after merge with developer
This commit is contained in:
parent
afb91b49db
commit
6f27126f5e
|
@ -7,13 +7,22 @@ import { getMessageById } from '../database/services/Message';
|
|||
import { MESSAGE_TYPE_LOAD_NEXT_CHUNK } from '../../constants/messageTypeLoad';
|
||||
import { generateLoadMoreId } from '../utils';
|
||||
import updateMessages from './updateMessages';
|
||||
import { IMessage, TMessageModel } from '../../definitions';
|
||||
import RocketChat from '../rocketchat';
|
||||
|
||||
const COUNT = 50;
|
||||
|
||||
export default function loadNextMessages(args) {
|
||||
interface ILoadNextMessages {
|
||||
rid: string;
|
||||
ts: string;
|
||||
tmid: string;
|
||||
loaderItem: TMessageModel;
|
||||
}
|
||||
|
||||
export default function loadNextMessages(args: ILoadNextMessages): Promise<IMessage | []> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const data = await this.methodCallWrapper('loadNextMessages', args.rid, args.ts, COUNT);
|
||||
const data = await RocketChat.methodCallWrapper('loadNextMessages', args.rid, args.ts, COUNT);
|
||||
let messages = EJSON.fromJSONValue(data?.messages);
|
||||
messages = orderBy(messages, 'ts');
|
||||
if (messages?.length) {
|
||||
|
@ -31,9 +40,8 @@ export default function loadNextMessages(args) {
|
|||
}
|
||||
await updateMessages({ rid: args.rid, update: messages, loaderItem: args.loaderItem });
|
||||
return resolve(messages);
|
||||
} else {
|
||||
return resolve([]);
|
||||
}
|
||||
return resolve([]);
|
||||
} catch (e) {
|
||||
log(e);
|
||||
reject(e);
|
Loading…
Reference in New Issue