Chore: Migrate readMessages to TS (#3669)
* Migrate readMessages to TS * Update IRocketChat interface
This commit is contained in:
parent
2d1b093666
commit
6839a6e548
|
@ -0,0 +1,5 @@
|
||||||
|
import { Rocketchat } from '@rocket.chat/sdk';
|
||||||
|
|
||||||
|
export interface IRocketChat {
|
||||||
|
sdk: typeof Rocketchat;
|
||||||
|
}
|
|
@ -1,7 +1,9 @@
|
||||||
import database from '../database';
|
import database from '../database';
|
||||||
import log from '../../utils/log';
|
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 {
|
try {
|
||||||
const db = database.active;
|
const db = database.active;
|
||||||
const subscription = await db.get('subscriptions').find(rid);
|
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
|
// RC 0.61.0
|
||||||
await this.sdk.post('subscriptions.read', { rid });
|
await this.sdk.post('subscriptions.read', { rid });
|
||||||
|
|
||||||
await db.action(async () => {
|
await db.write(async () => {
|
||||||
try {
|
try {
|
||||||
await subscription.update(s => {
|
await subscription.update((s: TSubscriptionModel) => {
|
||||||
s.open = true;
|
s.open = true;
|
||||||
s.alert = false;
|
s.alert = false;
|
||||||
s.unread = 0;
|
s.unread = 0;
|
Loading…
Reference in New Issue