From 6f27126f5e7b0121b633c987a233618547608efb Mon Sep 17 00:00:00 2001 From: Alex Junior Date: Mon, 21 Feb 2022 15:04:17 -0300 Subject: [PATCH] Chore: Migrate methods/loadNextMessages to typescript (#3719) * feat: update loadNextMessages to ts * minor tweak * chore: minor tweaks after merge with developer --- .../{loadNextMessages.js => loadNextMessages.ts} | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) rename app/lib/methods/{loadNextMessages.js => loadNextMessages.ts} (74%) diff --git a/app/lib/methods/loadNextMessages.js b/app/lib/methods/loadNextMessages.ts similarity index 74% rename from app/lib/methods/loadNextMessages.js rename to app/lib/methods/loadNextMessages.ts index 3fe728512..74f91d1f2 100644 --- a/app/lib/methods/loadNextMessages.js +++ b/app/lib/methods/loadNextMessages.ts @@ -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 { 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);