聊天:精简未读消息数的处理逻辑

This commit is contained in:
liangtongchuan
2021-03-11 10:44:20 +08:00
parent cce6a5af5e
commit 7da2044d0f
3 changed files with 20 additions and 19 deletions
+9 -2
View File
@@ -8,6 +8,8 @@ export class PrivateChatRec {
lastReadTime: Date; // 最后查看时间,用来检查未读消息数
@prop({ required: true })
lastChatTime: Date; // 最后聊天时间
@prop({ required: true, default: 0 })
unreadCnt: number; // 未读消息数
}
/**
@@ -50,8 +52,13 @@ export default class ChatInfo extends BaseModel {
return result;
}
public static async updateReadTime(roleId: string, targetRoleId: string, time: Date) {
const result: ChatInfoType = await ChatInfoModel.findOneAndUpdate({ roleId, 'recentPrivateChats.targetRoleId': targetRoleId }, { 'recentPrivateChats.$.lastReadTime': time }, { new: true }).select('-_id').lean();
public static async updateReadInfo(roleId: string, targetRoleId: string, time: Date) {
const result: ChatInfoType = await ChatInfoModel
.findOneAndUpdate(
{ roleId, 'recentPrivateChats.targetRoleId': targetRoleId },
{ 'recentPrivateChats.$.lastReadTime': time, 'recentPrivateChats.$.unreadCnt': 0 },
{ new: true })
.select('-_id').lean();
return result;
}
}