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:
Alex Junior 2022-02-21 15:04:17 -03:00 committed by GitHub
parent afb91b49db
commit 6f27126f5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 4 deletions

View File

@ -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);