From 5b3eabe7534ae5af0a0dc2523bb5aba92bfd466e Mon Sep 17 00:00:00 2001 From: AlexAlexandre Date: Wed, 9 Feb 2022 14:00:09 -0300 Subject: [PATCH 1/7] chore: change loadMessagesForRoom to typescript --- app/definitions/IRocketChat.ts | 8 +++++--- app/definitions/IRoom.ts | 1 + ...adMessagesForRoom.js => loadMessagesForRoom.ts} | 14 +++++++++----- 3 files changed, 15 insertions(+), 8 deletions(-) rename app/lib/methods/{loadMessagesForRoom.js => loadMessagesForRoom.ts} (72%) diff --git a/app/definitions/IRocketChat.ts b/app/definitions/IRocketChat.ts index 0db51320c8..3196647008 100644 --- a/app/definitions/IRocketChat.ts +++ b/app/definitions/IRocketChat.ts @@ -1,5 +1,7 @@ -import { Rocketchat } from '@rocket.chat/sdk'; +import rocketchat from '../lib/rocketchat'; -export interface IRocketChat { - sdk: typeof Rocketchat; +type TRocketChat = typeof rocketchat; + +export interface IRocketChat extends TRocketChat { + sdk: any; } diff --git a/app/definitions/IRoom.ts b/app/definitions/IRoom.ts index 503ea4dd72..be63378be9 100644 --- a/app/definitions/IRoom.ts +++ b/app/definitions/IRoom.ts @@ -22,6 +22,7 @@ export interface IRoom { tags?: string[]; e2eKeyId?: string; avatarETag?: string; + latest?: string; } export type TRoomModel = IRoom & Model; diff --git a/app/lib/methods/loadMessagesForRoom.js b/app/lib/methods/loadMessagesForRoom.ts similarity index 72% rename from app/lib/methods/loadMessagesForRoom.js rename to app/lib/methods/loadMessagesForRoom.ts index 4a11bcc8ce..e8d6619b77 100644 --- a/app/lib/methods/loadMessagesForRoom.js +++ b/app/lib/methods/loadMessagesForRoom.ts @@ -5,11 +5,13 @@ import log from '../../utils/log'; import { getMessageById } from '../database/services/Message'; import { generateLoadMoreId } from '../utils'; import updateMessages from './updateMessages'; +import { IRocketChat } from '../../definitions/IRocketChat'; +import { IMessage, IRoom, SubscriptionType } from '../../definitions'; const COUNT = 50; -async function load({ rid: roomId, latest, t }) { - let params = { roomId, count: COUNT }; +async function load(this: IRocketChat, { rid: roomId, latest, t }: Pick) { + let params = { roomId, count: COUNT } as { roomId: string; count: number; latest: string }; if (latest) { params = { ...params, latest: new Date(latest).toISOString() }; } @@ -27,7 +29,10 @@ async function load({ rid: roomId, latest, t }) { return data.messages; } -export default function loadMessagesForRoom(args) { +export default function loadMessagesForRoom( + this: IRocketChat, + args: { rid: string; t: SubscriptionType; latest: string; loaderItem: IRoom } +): Promise { return new Promise(async (resolve, reject) => { try { const data = await load.call(this, args); @@ -46,9 +51,8 @@ export default function loadMessagesForRoom(args) { } await updateMessages({ rid: args.rid, update: data, loaderItem: args.loaderItem }); return resolve(data); - } else { - return resolve([]); } + return resolve([]); } catch (e) { log(e); reject(e); From 536e96f619447e804d00be4e421a3754fa34fbee Mon Sep 17 00:00:00 2001 From: AlexAlexandre Date: Sun, 13 Feb 2022 21:08:14 -0300 Subject: [PATCH 2/7] minor tweak --- app/lib/methods/loadMessagesForRoom.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/lib/methods/loadMessagesForRoom.ts b/app/lib/methods/loadMessagesForRoom.ts index e8d6619b77..3f3e54c933 100644 --- a/app/lib/methods/loadMessagesForRoom.ts +++ b/app/lib/methods/loadMessagesForRoom.ts @@ -6,7 +6,7 @@ import { getMessageById } from '../database/services/Message'; import { generateLoadMoreId } from '../utils'; import updateMessages from './updateMessages'; import { IRocketChat } from '../../definitions/IRocketChat'; -import { IMessage, IRoom, SubscriptionType } from '../../definitions'; +import { IMessage, IRoom, SubscriptionType, TMessageModel } from '../../definitions'; const COUNT = 50; @@ -31,7 +31,7 @@ async function load(this: IRocketChat, { rid: roomId, latest, t }: Pick { return new Promise(async (resolve, reject) => { try { From ee311cdabe48777ef61e17322a668a3b6c2a55b8 Mon Sep 17 00:00:00 2001 From: AlexAlexandre Date: Mon, 14 Feb 2022 21:42:53 -0300 Subject: [PATCH 3/7] chore: minor tweaks after merge with developer --- app/lib/methods/loadMessagesForRoom.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/lib/methods/loadMessagesForRoom.ts b/app/lib/methods/loadMessagesForRoom.ts index 3f3e54c933..b793fb371b 100644 --- a/app/lib/methods/loadMessagesForRoom.ts +++ b/app/lib/methods/loadMessagesForRoom.ts @@ -7,6 +7,7 @@ import { generateLoadMoreId } from '../utils'; import updateMessages from './updateMessages'; import { IRocketChat } from '../../definitions/IRocketChat'; import { IMessage, IRoom, SubscriptionType, TMessageModel } from '../../definitions'; +import sdk from '../rocketchat/services/sdk'; const COUNT = 50; @@ -22,7 +23,8 @@ async function load(this: IRocketChat, { rid: roomId, latest, t }: Pick Date: Tue, 15 Feb 2022 00:23:12 -0300 Subject: [PATCH 4/7] chore: minor tweaks after merge with developer --- app/lib/methods/loadMessagesForRoom.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/lib/methods/loadMessagesForRoom.ts b/app/lib/methods/loadMessagesForRoom.ts index b793fb371b..19e4bb815c 100644 --- a/app/lib/methods/loadMessagesForRoom.ts +++ b/app/lib/methods/loadMessagesForRoom.ts @@ -8,16 +8,17 @@ import updateMessages from './updateMessages'; import { IRocketChat } from '../../definitions/IRocketChat'; import { IMessage, IRoom, SubscriptionType, TMessageModel } from '../../definitions'; import sdk from '../rocketchat/services/sdk'; +import RocketChat from '../rocketchat'; const COUNT = 50; -async function load(this: IRocketChat, { rid: roomId, latest, t }: Pick) { +async function load({ rid: roomId, latest, t }: Pick) { let params = { roomId, count: COUNT } as { roomId: string; count: number; latest: string }; if (latest) { params = { ...params, latest: new Date(latest).toISOString() }; } - const apiType = this.roomTypeToApiType(t); + const apiType = RocketChat.roomTypeToApiType(t); if (!apiType) { return []; } From 301ddd957fc3e5200aae44c88aa577ceb30a493b Mon Sep 17 00:00:00 2001 From: AlexAlexandre Date: Tue, 15 Feb 2022 12:09:12 -0300 Subject: [PATCH 5/7] chore: minor tweak --- app/lib/methods/loadMessagesForRoom.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/lib/methods/loadMessagesForRoom.ts b/app/lib/methods/loadMessagesForRoom.ts index 19e4bb815c..dc5865e222 100644 --- a/app/lib/methods/loadMessagesForRoom.ts +++ b/app/lib/methods/loadMessagesForRoom.ts @@ -5,7 +5,6 @@ import log from '../../utils/log'; import { getMessageById } from '../database/services/Message'; import { generateLoadMoreId } from '../utils'; import updateMessages from './updateMessages'; -import { IRocketChat } from '../../definitions/IRocketChat'; import { IMessage, IRoom, SubscriptionType, TMessageModel } from '../../definitions'; import sdk from '../rocketchat/services/sdk'; import RocketChat from '../rocketchat'; @@ -32,13 +31,15 @@ async function load({ rid: roomId, latest, t }: Pick { +export default function loadMessagesForRoom(args: { + rid: string; + t: SubscriptionType; + latest: string; + loaderItem: TMessageModel; +}): Promise { return new Promise(async (resolve, reject) => { try { - const data = await load.call(this, args); + const data = await load(args); if (data?.length) { const lastMessage = data[data.length - 1]; const lastMessageRecord = await getMessageById(lastMessage._id); From d414ff50f4435b9394131adb1b680f814b8510ab Mon Sep 17 00:00:00 2001 From: AlexAlexandre Date: Wed, 16 Feb 2022 19:56:12 -0300 Subject: [PATCH 6/7] chore: minor tweaks --- app/lib/methods/loadMessagesForRoom.ts | 12 ++++++------ app/lib/methods/updateMessages.ts | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/lib/methods/loadMessagesForRoom.ts b/app/lib/methods/loadMessagesForRoom.ts index dc5865e222..2f3b730a12 100644 --- a/app/lib/methods/loadMessagesForRoom.ts +++ b/app/lib/methods/loadMessagesForRoom.ts @@ -5,19 +5,19 @@ import log from '../../utils/log'; import { getMessageById } from '../database/services/Message'; import { generateLoadMoreId } from '../utils'; import updateMessages from './updateMessages'; -import { IMessage, IRoom, SubscriptionType, TMessageModel } from '../../definitions'; +import { IMessage, TMessageModel } from '../../definitions'; import sdk from '../rocketchat/services/sdk'; -import RocketChat from '../rocketchat'; +import roomTypeToApiType, { RoomTypes } from '../rocketchat/methods/roomTypeToApiType'; const COUNT = 50; -async function load({ rid: roomId, latest, t }: Pick) { - let params = { roomId, count: COUNT } as { roomId: string; count: number; latest: string }; +async function load({ rid: roomId, latest, t }: { rid: string; latest?: string; t: RoomTypes }) { + let params = { roomId, count: COUNT } as { roomId: string; count: number; latest?: string }; if (latest) { params = { ...params, latest: new Date(latest).toISOString() }; } - const apiType = RocketChat.roomTypeToApiType(t); + const apiType = roomTypeToApiType(t); if (!apiType) { return []; } @@ -33,7 +33,7 @@ async function load({ rid: roomId, latest, t }: Pick { diff --git a/app/lib/methods/updateMessages.ts b/app/lib/methods/updateMessages.ts index f273aaeadb..7a91019243 100644 --- a/app/lib/methods/updateMessages.ts +++ b/app/lib/methods/updateMessages.ts @@ -13,7 +13,7 @@ import { getSubscriptionByRoomId } from '../database/services/Subscription'; interface IUpdateMessages { rid: string; update: IMessage[]; - remove: IMessage[]; + remove?: IMessage[]; loaderItem?: TMessageModel; } From 17950d3011fea7828a6c5d6e89696fbd054cce6c Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Thu, 17 Feb 2022 15:03:56 -0300 Subject: [PATCH 7/7] Fix return --- app/lib/methods/loadMessagesForRoom.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/lib/methods/loadMessagesForRoom.ts b/app/lib/methods/loadMessagesForRoom.ts index 2f3b730a12..db64a05caa 100644 --- a/app/lib/methods/loadMessagesForRoom.ts +++ b/app/lib/methods/loadMessagesForRoom.ts @@ -36,7 +36,7 @@ export default function loadMessagesForRoom(args: { t: RoomTypes; latest: string; loaderItem: TMessageModel; -}): Promise { +}): Promise { return new Promise(async (resolve, reject) => { try { const data = await load(args);