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;