聊天:精简未读消息数的处理逻辑
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user