聊天:登录时处理最近私聊过的用户信息

This commit is contained in:
liangtongchuan
2021-03-10 16:02:04 +08:00
parent b822337b82
commit 901995b8ba
3 changed files with 54 additions and 8 deletions
+11 -2
View File
@@ -1,9 +1,12 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
class PrivateChatRec {
export class PrivateChatRec {
@prop({ required: true, default: '' })
targetRoleId: string; // 聊天玩家 roleId
@prop({ required: false })
lastReadTime: Date; // 最后查看时间,用来检查未读消息数
@prop({ required: true })
lastChatTime: Date; // 最后聊天时间
}
@@ -26,7 +29,7 @@ export default class ChatInfo extends BaseModel {
BSSources: [string]; // 弹幕打开的消息来源
@prop({ required: true, default: '' })
bubbleId: string; // 气泡编号
@prop({ required: true, type: PrivateChatRec, default: [] })
@prop({ required: true, type: PrivateChatRec, default: [], _id: false })
recentPrivateChats: [PrivateChatRec]; // 最近聊天列表
public static async createInfo(data: ChatInfoParam) {
@@ -40,6 +43,12 @@ export default class ChatInfo extends BaseModel {
let result = await ChatInfoModel.findOne({ roleId }).select('-_id').lean();
return result;
}
public static async updateInfo(data: ChatInfoParam) {
const roleId = data.roleId!;
const result = await ChatInfoModel.findOneAndUpdate({ roleId }, { $set: { ...data } }, { new: true }).select('-_id').lean();
return result;
}
}