diff --git a/server/models/chat/inbox.ts b/server/models/chat/inbox.ts index 6161ea31..5ea0d005 100644 --- a/server/models/chat/inbox.ts +++ b/server/models/chat/inbox.ts @@ -57,6 +57,14 @@ export class Inbox extends TimeStamps implements Base { type: () => InboxMessage, }) message?: InboxMessage; + + /** + * 是否已读 + */ + @prop({ + default: false, + }) + readed: boolean; } export type InboxDocument = DocumentType; diff --git a/server/services/core/chat/inbox.service.dev.ts b/server/services/core/chat/inbox.service.dev.ts index b183ca67..663a7d7e 100644 --- a/server/services/core/chat/inbox.service.dev.ts +++ b/server/services/core/chat/inbox.service.dev.ts @@ -78,6 +78,11 @@ class InboxService extends TcService { }, }); this.registerAction('all', this.all); + this.registerAction('ack', this.ack, { + params: { + inboxItemId: 'string', + }, + }); } async appendMessage( @@ -152,6 +157,26 @@ class InboxService extends TcService { return await this.transformDocuments(ctx, {}, list); } + /** + * 标记收件箱内容已读 + */ + async ack(ctx: TcContext<{ inboxItemId: string }>) { + const inboxItemId = ctx.params.inboxItemId; + const userId = ctx.meta.userId; + + await this.adapter.model.updateOne( + { + _id: inboxItemId, + userId, + }, + { + readed: true, + } + ); + + return true; + } + /** * 发送通知群组信息发生变更 *