聊天:置顶和删除记录

This commit is contained in:
luying
2021-06-29 19:08:45 +08:00
parent 5822653d26
commit 79c8f1f9fa
4 changed files with 98 additions and 3 deletions

View File

@@ -10,6 +10,10 @@ export class PrivateChatRec {
lastChatTime: Date; // 最后聊天时间
@prop({ required: true, default: 0 })
unreadCnt: number; // 未读消息数
@prop({ required: true })
isTop: boolean; // 是否置顶
@prop({ required: true })
setTopTime: Date; // 置顶时间
}
/**
@@ -61,6 +65,26 @@ export default class ChatInfo extends BaseModel {
.select('-_id').lean();
return result;
}
public static async setTop(roleId: string, targetRoleId: string, isTop: boolean, time: Date) {
const result: ChatInfoType = await ChatInfoModel
.findOneAndUpdate(
{ roleId, 'recentPrivateChats.targetRoleId': targetRoleId },
{ 'recentPrivateChats.$.isTop': isTop, 'recentPrivateChats.$.setTopTime': time },
{ new: true })
.select('-_id').lean();
return result;
}
public static async delMsg(roleId: string, targetRoleId: string) {
const result: ChatInfoType = await ChatInfoModel
.findOneAndUpdate(
{ roleId },
{ $pull: { recentPrivateChats: { targetRoleId } } },
{ new: true })
.select('-_id').lean();
return result;
}
}
export const ChatInfoModel = getModelForClass(ChatInfo);