From 6839a6e548470c3f1f1e6e60bd4a0836fae2df98 Mon Sep 17 00:00:00 2001 From: Gerzon Z Date: Mon, 7 Feb 2022 14:54:19 -0400 Subject: [PATCH] Chore: Migrate readMessages to TS (#3669) * Migrate readMessages to TS * Update IRocketChat interface --- app/definitions/IRocketChat.ts | 5 +++++ app/lib/methods/{readMessages.js => readMessages.ts} | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 app/definitions/IRocketChat.ts rename app/lib/methods/{readMessages.js => readMessages.ts} (61%) diff --git a/app/definitions/IRocketChat.ts b/app/definitions/IRocketChat.ts new file mode 100644 index 000000000..0db51320c --- /dev/null +++ b/app/definitions/IRocketChat.ts @@ -0,0 +1,5 @@ +import { Rocketchat } from '@rocket.chat/sdk'; + +export interface IRocketChat { + sdk: typeof Rocketchat; +} diff --git a/app/lib/methods/readMessages.js b/app/lib/methods/readMessages.ts similarity index 61% rename from app/lib/methods/readMessages.js rename to app/lib/methods/readMessages.ts index 7d2d58de1..344ce9ebb 100644 --- a/app/lib/methods/readMessages.js +++ b/app/lib/methods/readMessages.ts @@ -1,7 +1,9 @@ import database from '../database'; import log from '../../utils/log'; +import { TSubscriptionModel } from '../../definitions'; +import { IRocketChat } from '../../definitions/IRocketChat'; -export default async function readMessages(rid, ls, updateLastOpen = false) { +export default async function readMessages(this: IRocketChat, rid: string, ls: Date, updateLastOpen = false): Promise { try { const db = database.active; const subscription = await db.get('subscriptions').find(rid); @@ -9,9 +11,9 @@ export default async function readMessages(rid, ls, updateLastOpen = false) { // RC 0.61.0 await this.sdk.post('subscriptions.read', { rid }); - await db.action(async () => { + await db.write(async () => { try { - await subscription.update(s => { + await subscription.update((s: TSubscriptionModel) => { s.open = true; s.alert = false; s.unread = 0;