聊天:置顶和删除记录
This commit is contained in:
@@ -2,7 +2,7 @@ import { CHANNEL_PREFIX, MSG_SOURCE, CHANNEL_TYPE } from './../../../consts/cons
|
|||||||
import { Application, BackendSession } from 'pinus';
|
import { Application, BackendSession } from 'pinus';
|
||||||
import { resResult } from '../../../pubUtils/util';
|
import { resResult } from '../../../pubUtils/util';
|
||||||
import { DEFAULT_MSG_PER_PAGE, STATUS, TASK_TYPE } from '../../../consts';
|
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 { getSimpleRoleInfo } from '../../../services/roleService';
|
||||||
import { checkActivityTask, checkTaskWithArgs } from '../../../services/taskService';
|
import { checkActivityTask, checkTaskWithArgs } from '../../../services/taskService';
|
||||||
|
|
||||||
@@ -200,6 +200,40 @@ export class ChatHandler {
|
|||||||
return resResult(STATUS.SUCCESS, result);
|
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 举报玩家的消息
|
* @description 举报玩家的消息
|
||||||
* @param {{targetRoleId: string, targetMsgCode: string; reason: number}} msg 被举报玩家的 Id,被举报的消息编号,举报原因
|
* @param {{targetRoleId: string, targetMsgCode: string; reason: number}} msg 被举报玩家的 Id,被举报的消息编号,举报原因
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ export async function recentGuildMsgs(guildCode: string, count?: number) {
|
|||||||
function createChatRec(sender: boolean, curTime: Date, targetRoleId) {
|
function createChatRec(sender: boolean, curTime: Date, targetRoleId) {
|
||||||
const result: PrivateChatRec = {
|
const result: PrivateChatRec = {
|
||||||
// 接收者没有阅读时间,发送者未读数为 0
|
// 接收者没有阅读时间,发送者未读数为 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;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -282,7 +282,17 @@ export async function roleChatInfos(roleId: string, roleName: string) {
|
|||||||
export async function recentPrivateChatInfos(roleId: string, roleName: string) {
|
export async function recentPrivateChatInfos(roleId: string, roleName: string) {
|
||||||
const { recentPrivateChats } = await roleChatInfos(roleId, roleName);
|
const { recentPrivateChats } = await roleChatInfos(roleId, roleName);
|
||||||
recentPrivateChats
|
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);
|
.splice(CHAT_SYSTEM.RECENT_PRIVATE_CHATS_CNT);
|
||||||
if (!recentPrivateChats || !recentPrivateChats.length) return null;
|
if (!recentPrivateChats || !recentPrivateChats.length) return null;
|
||||||
|
|
||||||
@@ -310,6 +320,31 @@ export async function updatePrivateMsgReadInfo(roleId: string, targetRoleId: str
|
|||||||
return chatRec;
|
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 发送组队一键邀请消息
|
* @description 发送组队一键邀请消息
|
||||||
* @param {string} teamCode 队伍唯一标识
|
* @param {string} teamCode 队伍唯一标识
|
||||||
|
|||||||
@@ -337,6 +337,8 @@ export const STATUS = {
|
|||||||
// 社交相关状态 40000 - 49999
|
// 社交相关状态 40000 - 49999
|
||||||
SYS_CHANNEL_AUTH_NOT_ENOUGH: { code: 40000, simStr: '无法在系统频道发送消息' },
|
SYS_CHANNEL_AUTH_NOT_ENOUGH: { code: 40000, simStr: '无法在系统频道发送消息' },
|
||||||
UPDATE_PRIVATE_MSG_READ_TIME_ERR: { code: 40001, simStr: '更新私聊阅读时间失败' },
|
UPDATE_PRIVATE_MSG_READ_TIME_ERR: { code: 40001, simStr: '更新私聊阅读时间失败' },
|
||||||
|
SET_PRIVATE_MSG_TOP_ERR: { code: 40002, simStr: '设置置顶失败' },
|
||||||
|
DEL_PRIVATE_MSG_ERR: { code: 40003, simStr: '删除失败' },
|
||||||
// 运营模块相关状态 50000 - 59999
|
// 运营模块相关状态 50000 - 59999
|
||||||
ACTIVITY_MISSING: { code: 50000, simStr: '活动丢失' },
|
ACTIVITY_MISSING: { code: 50000, simStr: '活动丢失' },
|
||||||
ACTIVITY_DATA_ERROR: { code: 50001, simStr: '数据错误' },
|
ACTIVITY_DATA_ERROR: { code: 50001, simStr: '数据错误' },
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ export class PrivateChatRec {
|
|||||||
lastChatTime: Date; // 最后聊天时间
|
lastChatTime: Date; // 最后聊天时间
|
||||||
@prop({ required: true, default: 0 })
|
@prop({ required: true, default: 0 })
|
||||||
unreadCnt: number; // 未读消息数
|
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();
|
.select('-_id').lean();
|
||||||
return result;
|
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);
|
export const ChatInfoModel = getModelForClass(ChatInfo);
|
||||||
|
|||||||
Reference in New Issue
Block a user