import Inject, { RegisterTransient } from "@entity-access/entity-access/dist/di/di.js"; import UpdateUnreadCounts from "../../workflows/email/UpdateUnreadCounts.js"; import SocialMailContext from "../../model/SocialMailContext.js"; import Sql from "@entity-access/entity-access/dist/sql/Sql.js"; import { AppWorkflowContext } from "../../workflows/AppWorkflowContext.js"; @RegisterTransient export default class UnreadCountService { @Inject workflowContext: AppWorkflowContext; @Inject db: SocialMailContext; async updateCounts({ emailID, mailboxID, emailAddressID}) { await this.workflowContext.queue(UpdateUnreadCounts, { mailboxID, emailAddressID }); // const mn = ServiceProvider.resolve(this, MailboxNamespace); // mn.newMail(mailboxID, emailAddressID, emailID); } async markAsRead(activity: { mailboxID, emailID, emailAddressID }) { const { db } = this; const updated = await db.mailboxContactEmails .where(activity, (x, p) => x.emailID === p.emailID && x.emailAddressID === p.emailAddressID && x.mailboxID === p.mailboxID && x.timeRead === null) .update((x) => ({ timeRead: Sql.date.now()})); if (updated) { await this.updateCounts(activity); } } }