聊天:置顶和删除记录

This commit is contained in:
luying
2021-06-29 19:09:04 +08:00
parent 5822653d26
commit 79c8f1f9fa
4 changed files with 98 additions and 3 deletions
@@ -2,7 +2,7 @@ import { CHANNEL_PREFIX, MSG_SOURCE, CHANNEL_TYPE } from './../../../consts/cons
import { Application, BackendSession } from 'pinus';
import { resResult } from '../../../pubUtils/util';
import { DEFAULT_MSG_PER_PAGE, STATUS, TASK_TYPE } from '../../../consts';
import { createAccuseData, createGroupMsg, createPrivateMsg, getPrivateMessages, pushGroupMsgToRoom, pushMsgToRole, updatePrivateMsgReadInfo, recentPrivateChatInfos, recentWorldMsgs, recentSysMsgs, recentGuildMsgs } from '../../../services/chatService';
import { createAccuseData, createGroupMsg, createPrivateMsg, getPrivateMessages, pushGroupMsgToRoom, pushMsgToRole, updatePrivateMsgReadInfo, recentPrivateChatInfos, recentWorldMsgs, recentSysMsgs, recentGuildMsgs, updatePrivateMsgIsTop,delPrivateMsg } from '../../../services/chatService';
import { getSimpleRoleInfo } from '../../../services/roleService';
import { checkActivityTask, checkTaskWithArgs } from '../../../services/taskService';
@@ -200,6 +200,40 @@ export class ChatHandler {
return resResult(STATUS.SUCCESS, result);
}
/**
* @description 设置置顶
* @param {{ targetRoleId: string, isTop: boolean }} msg
* @param {BackendSession} session
* @returns
* @memberof ChatHandler
*/
async setPrivateMessageTop(msg: { targetRoleId: string, isTop: boolean }, session: BackendSession) {
const roleId = session.get('roleId');
const { targetRoleId, isTop } = msg;
const result = await updatePrivateMsgIsTop(roleId, targetRoleId, isTop);
if (!result) {
return resResult(STATUS.SET_PRIVATE_MSG_TOP_ERR);
}
return resResult(STATUS.SUCCESS, result);
}
/**
* @description 删除私聊
* @param {{ targetRoleId: string }} msg
* @param {BackendSession} session
* @returns
* @memberof ChatHandler
*/
async delPrivateMessage(msg: { targetRoleId: string }, session: BackendSession) {
const roleId = session.get('roleId');
const { targetRoleId } = msg;
const result = await delPrivateMsg(roleId, targetRoleId);
if (!result) {
return resResult(STATUS.DEL_PRIVATE_MSG_ERR);
}
return resResult(STATUS.SUCCESS, result);
}
/**
* @description 举报玩家的消息
* @param {{targetRoleId: string, targetMsgCode: string; reason: number}} msg 被举报玩家的 Id,被举报的消息编号,举报原因
+37 -2
View File
@@ -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 队伍唯一标识