Chore: Migrate readMessages to TS (#3669)

* Migrate readMessages to TS

* Update IRocketChat interface
This commit is contained in:
Gerzon Z 2022-02-07 14:54:19 -04:00 committed by GitHub
parent 2d1b093666
commit 6839a6e548
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -0,0 +1,5 @@
import { Rocketchat } from '@rocket.chat/sdk';
export interface IRocketChat {
sdk: typeof Rocketchat;
}

View File

@ -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<void> {
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;