聊天:最近私聊历史相关逻辑
This commit is contained in:
@@ -19,7 +19,7 @@ import { GuildModel } from '../../../db/Guild';
|
||||
import { gameData } from '../../../pubUtils/data';
|
||||
|
||||
import { getMails } from '../../../services/mailService';
|
||||
import { addRoleToGuildChannel, addRoleToSysChannel, addRoleToWorldChannel, leaveGuildChannel, leaveSysChannel, leaveWorldChannel } from '../../../services/chatService';
|
||||
import { addRoleToGuildChannel, addRoleToSysChannel, addRoleToWorldChannel, leaveGuildChannel, leaveSysChannel, leaveWorldChannel, recentPrivateChatInfos } from '../../../services/chatService';
|
||||
import { reportOneOnline } from '../../../services/timeTaskService';
|
||||
export default function (app: Application) {
|
||||
return new EntryHandler(app);
|
||||
@@ -109,6 +109,11 @@ export class EntryHandler {
|
||||
role['apJson'] = apJson;
|
||||
role['mails'] = mails;
|
||||
|
||||
const recentPrivateChats = await recentPrivateChatInfos(role.roleId, role.roleName);
|
||||
if (recentPrivateChats) {
|
||||
role['recentPrivateChats'] = recentPrivateChats;
|
||||
}
|
||||
|
||||
if(role.hasGuild) {
|
||||
let userGuild = await UserGuildModel.getMyGuild(role.roleId, USER_GUILD_SELECT.ENTRY );
|
||||
if(userGuild) {
|
||||
|
||||
@@ -9,12 +9,13 @@ import { PrivateMessageModel, PrivateMessageParam, PrivateMessageType } from './
|
||||
import { GroupMessageParam, GroupMessageType } from '../db/GroupMessage';
|
||||
import { genCode, resResult } from '../pubUtils/util';
|
||||
import { pinus } from 'pinus';
|
||||
import { CHANNEL_PREFIX, MSG_CODE_LEN, MSG_SOURCE, MSG_STATUS, MSG_TYPE, ON_GROUP_MSG_ROUTE, ON_MSG_ROUTE, RICH_TEXT_TABLE } from '../consts';
|
||||
import { CHANNEL_PREFIX, MSG_CODE_LEN, MSG_SOURCE, MSG_STATUS, MSG_TYPE, ON_GROUP_MSG_ROUTE, ON_MSG_ROUTE, RICH_TEXT_TABLE, RECENT_PRIVATE_CHATS_CNT, MAX_PRIVATE_MSGS } from '../consts';
|
||||
import { addRedisChannel, getRoleOnlineInfo, redisChannelServer } from './redisService';
|
||||
import { crc32 } from 'crc';
|
||||
import { HeroType } from '../db/Hero';
|
||||
import { GuildType } from '../db/Guild';
|
||||
import { GuildTrainType } from '../db/GuildTrain';
|
||||
import { ChatInfoModel } from '../db/ChatInfo';
|
||||
|
||||
/**
|
||||
* @description 生成私聊房间号
|
||||
@@ -272,3 +273,37 @@ export async function pushGuildBossSucMsg(roleId: string, roleName: string, guil
|
||||
await pushGroupMsgToRoom(groupRoomId(CHANNEL_PREFIX.GUILD, guildCode), msgData);
|
||||
return msgData;
|
||||
}
|
||||
|
||||
export async function roleChatInfos(roleId: string, roleName: string) {
|
||||
let result = await ChatInfoModel.findInfo(roleId);
|
||||
if (!result) {
|
||||
result = await ChatInfoModel.createInfo({ roleId, roleName });
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function recentPrivateChatInfos(roleId: string, roleName: string) {
|
||||
const { recentPrivateChats } = await roleChatInfos(roleId, roleName);
|
||||
const sortedChats = recentPrivateChats
|
||||
.sort((a, b) => a.lastChatTime.getTime() - b.lastChatTime.getTime())
|
||||
.splice(RECENT_PRIVATE_CHATS_CNT);
|
||||
if (!sortedChats || !sortedChats.length) return null;
|
||||
|
||||
const unreadChats = sortedChats.filter(chat => { return chat.lastChatTime > chat.lastReadTime });
|
||||
let unreadMsgs = {};
|
||||
for (let { targetRoleId, lastReadTime } of unreadChats) {
|
||||
const msgs = await PrivateMessageModel.getMsgsByTime(privateRoomId(roleId, targetRoleId), lastReadTime, MAX_PRIVATE_MSGS);
|
||||
unreadMsgs[targetRoleId] = msgs;
|
||||
}
|
||||
|
||||
const roleInfos = await RoleModel.findRoleByField('roleId', sortedChats.map(chat => { return chat.targetRoleId }));
|
||||
const chatInfos = sortedChats.map( chat => {
|
||||
for (let { roleId: targetRoleId, quitTime, roleName: targetRoleName, title, guildName, headHid, sHid, lv } of roleInfos) {
|
||||
if (targetRoleId === chat.targetRoleId) {
|
||||
const unreadCnt = unreadMsgs[targetRoleId] ? unreadMsgs[targetRoleId].length : 0;
|
||||
return { ...chat, quitTime, targetRoleName, title, guildName, headHid, sHid, lv, unreadCnt };
|
||||
}
|
||||
}
|
||||
});
|
||||
return chatInfos;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user