聊天:置顶和删除记录
This commit is contained in:
@@ -238,7 +238,7 @@ export async function recentGuildMsgs(guildCode: string, count?: number) {
|
||||
function createChatRec(sender: boolean, curTime: Date, targetRoleId) {
|
||||
const result: PrivateChatRec = {
|
||||
// 接收者没有阅读时间,发送者未读数为 0
|
||||
targetRoleId, lastChatTime: curTime, lastReadTime: sender ? curTime : null, unreadCnt: sender ? 0 : 1
|
||||
targetRoleId, lastChatTime: curTime, lastReadTime: sender ? curTime : null, unreadCnt: sender ? 0 : 1, isTop: false, setTopTime: curTime
|
||||
};
|
||||
return result;
|
||||
}
|
||||
@@ -282,7 +282,17 @@ export async function roleChatInfos(roleId: string, roleName: string) {
|
||||
export async function recentPrivateChatInfos(roleId: string, roleName: string) {
|
||||
const { recentPrivateChats } = await roleChatInfos(roleId, roleName);
|
||||
recentPrivateChats
|
||||
.sort((a, b) => a.lastChatTime.getTime() - b.lastChatTime.getTime())
|
||||
.sort((a, b) => {
|
||||
if(a.isTop || b.isTop) {
|
||||
if(a.isTop && b.isTop) {
|
||||
return a.setTopTime.getTime() - b.setTopTime.getTime()
|
||||
} else {
|
||||
return (b.isTop?1:0) - (a.isTop?1:0);
|
||||
}
|
||||
} else {
|
||||
return a.lastChatTime.getTime() - b.lastChatTime.getTime()
|
||||
}
|
||||
})
|
||||
.splice(CHAT_SYSTEM.RECENT_PRIVATE_CHATS_CNT);
|
||||
if (!recentPrivateChats || !recentPrivateChats.length) return null;
|
||||
|
||||
@@ -310,6 +320,31 @@ export async function updatePrivateMsgReadInfo(roleId: string, targetRoleId: str
|
||||
return chatRec;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 查看消息时更新查看时间和未读消息数
|
||||
*/
|
||||
export async function updatePrivateMsgIsTop(roleId: string, targetRoleId: string, isTop: boolean) {
|
||||
const time = new Date();
|
||||
const chatInfo = await ChatInfoModel.setTop(roleId, targetRoleId, isTop, time);
|
||||
if (!chatInfo || !chatInfo.recentPrivateChats) {
|
||||
return null;
|
||||
}
|
||||
const chatRec = chatInfo.recentPrivateChats.find(rec => { return rec.targetRoleId === targetRoleId });
|
||||
return chatRec;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 查看消息时更新查看时间和未读消息数
|
||||
*/
|
||||
export async function delPrivateMsg(roleId: string, targetRoleId: string) {
|
||||
const chatInfo = await ChatInfoModel.delMsg(roleId, targetRoleId);
|
||||
if (!chatInfo || !chatInfo.recentPrivateChats) {
|
||||
return null;
|
||||
}
|
||||
return { targetRoleId };
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description 发送组队一键邀请消息
|
||||
* @param {string} teamCode 队伍唯一标识
|
||||
|
||||
Reference in New Issue
Block a user