feat(聊天): 战区频道

This commit is contained in:
luying
2023-03-18 18:05:09 +08:00
parent e52c7b5241
commit 2d8abaaaff
5 changed files with 47 additions and 25 deletions

View File

@@ -1,6 +1,6 @@
import { CHANNEL_PREFIX, MSG_SOURCE, getChannelType } from './../../../consts/constModules/chatConst';
import { Application, BackendSession, HandlerService, } from 'pinus';
import { resResult } from '../../../pubUtils/util';
import { genCode, 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, updatePrivateMsgIsTop, delPrivateMsg, recentServerGroupMsgs, recentLeagueMsgs } from '../../../services/chatService';
import { getSimpleRoleInfo } from '../../../services/roleService';
@@ -8,8 +8,9 @@ import { checkTask } from '../../../services/task/taskService';
import { RoleModel } from '../../../db/Role';
import { getFriendRelationType } from '../../../services/friendService';
import { GVGLeagueModel } from '../../../db/GVGLeague';
import { getGVGGroupIdOfServer } from '../../../services/serverService';
import { getAllGroupOfServer } from '../../../services/serverService';
import { getGuildCodeString } from '../../../services/gvg/gvgRecService';
import { GroupMessageType } from '../../../db/GroupMessage';
export default function (app: Application) {
@@ -36,22 +37,26 @@ export class ChatHandler {
const guildCode = session.get('guildCode');
const sid = session.get('sid');
let channelId = '', otherInfo = '';
if (channel === CHANNEL_PREFIX.WORLD) channelId = `${serverId}`;
if (channel === CHANNEL_PREFIX.GUILD) channelId = guildCode;
let channelIds: (string|number)[] = [], otherInfo = '';
if (channel === CHANNEL_PREFIX.WORLD) channelIds.push(serverId);
if (channel === CHANNEL_PREFIX.GUILD) channelIds.push(guildCode);
if (channel === CHANNEL_PREFIX.GVG) {
let groupId = await getGVGGroupIdOfServer(serverId);
channelId = `${groupId}`;
let groupIds = await getAllGroupOfServer(serverId);
groupIds.forEach(groupId => channelIds.push(groupId));
otherInfo = genCode(10);
}
if (channel == CHANNEL_PREFIX.LEAGUE) {
let myLeague = await GVGLeagueModel.findLeagueByGuild(guildCode);
if(!myLeague) return resResult(STATUS.GVG_NOT_JOIN_LEAGUE);
channelId = myLeague.leagueCode;
channelIds.push(myLeague.leagueCode);
otherInfo = getGuildCodeString(myLeague);
}
const msgData = await createGroupMsg(roleId, roleName, channel, channelId, type, MSG_SOURCE.ROLE_SEND_TEXT, content, targetRoleId, targetMsgCode, otherInfo);
if (!msgData) return resResult(STATUS.WRONG_PARMS);
await pushGroupMsgToRoom(msgData);
let msgData: GroupMessageType;
for(let channelId of channelIds) {
msgData = await createGroupMsg(roleId, roleName, channel, `${channelId}`, type, MSG_SOURCE.ROLE_SEND_TEXT, content, targetRoleId, targetMsgCode, otherInfo);
if (!msgData) return resResult(STATUS.WRONG_PARMS);
await pushGroupMsgToRoom(msgData);
}
// 任务
await checkTask(serverId, roleId, sid, TASK_TYPE.CHAT, { chatType: getChannelType(channel) });

View File

@@ -17,7 +17,7 @@ import { sendMessageToAllWithSuc, sendMessageToCityWithSuc, sendMessageToGuildWi
import { comBtlLvInvalid } from './comBattleService';
import { gameData } from '../pubUtils/data';
import { RegionModel } from '../db/Region';
import { getGVGGroupIdOfServer, getGVGServersByGroupId } from './serverService';
import { getAllGroupOfServer, getGVGGroupIdOfServer, getGVGServersByGroupId } from './serverService';
import { GVGLeagueModel } from '../db/GVGLeague';
export * from './chatChannelService';
@@ -209,14 +209,23 @@ function sendFromRole(msg: GroupMessageParam) {
* @param {number} [count] 期望获取的消息数
* @returns
*/
async function recentGroupMsgs(roomId: string, count?: number) {
const msgs = await GroupMessageModel.getMsgs(roomId, Infinity, count || CHAT_SYSTEM.RECENT_GROUP_MSGS_CNT);
async function recentGroupMsgs(roomIds: string[], count?: number) {
const msgs = await GroupMessageModel.getMsgs(roomIds, Infinity, count || CHAT_SYSTEM.RECENT_GROUP_MSGS_CNT);
const roleIds = msgs
.map(msg => { return sendFromRole(msg) ? msg.roleId : null })
.filter(roleId => !!roleId);
const roleInfos = await getSimpleRoleInfos(roleIds);
const infos: string[] = [];
const filterMsgs = msgs.filter(msg => {
if(!msg.otherInfo) return true;
if(infos.indexOf(msg.otherInfo) == -1) {
infos.push(msg.otherInfo);
return true
}
return false;
})
const result = roleInfos ?
msgs.map(msg => {
filterMsgs.map(msg => {
if (!sendFromRole(msg)) return msg;
for (let roleInfo of roleInfos) {
if (roleInfo.roleId === msg.roleId) {
@@ -224,7 +233,7 @@ async function recentGroupMsgs(roomId: string, count?: number) {
}
}
})
: msgs;
: filterMsgs;
return result.filter(cur => cur) || [];
}
@@ -236,8 +245,9 @@ async function recentGroupMsgs(roomId: string, count?: number) {
* @returns
*/
export async function recentServerGroupMsgs(serverId: number, count?: number) {
let groupId = await getGVGGroupIdOfServer(serverId);
const result = await recentGroupMsgs(groupRoomId(CHANNEL_PREFIX.GVG, groupId), count);
let groupIds = await getAllGroupOfServer(serverId);
let roomIds = groupIds.map(groupId => groupRoomId(CHANNEL_PREFIX.GVG, groupId));
const result = await recentGroupMsgs(roomIds, count);
return result;
}
@@ -249,7 +259,7 @@ export async function recentServerGroupMsgs(serverId: number, count?: number) {
* @returns
*/
export async function recentWorldMsgs(serverId: number, count?: number) {
const result = await recentGroupMsgs(groupRoomId(CHANNEL_PREFIX.WORLD, serverId), count);
const result = await recentGroupMsgs([groupRoomId(CHANNEL_PREFIX.WORLD, serverId)], count);
return result;
}
@@ -261,7 +271,7 @@ export async function recentWorldMsgs(serverId: number, count?: number) {
* @returns
*/
export async function recentSysMsgs(serverId: number, count?: number) {
const result = await recentGroupMsgs(groupRoomId(CHANNEL_PREFIX.SYS, serverId), count);
const result = await recentGroupMsgs([groupRoomId(CHANNEL_PREFIX.SYS, serverId)], count);
return result;
}
@@ -274,7 +284,7 @@ export async function recentSysMsgs(serverId: number, count?: number) {
*/
export async function recentGuildMsgs(guildCode: string, count?: number) {
if(!guildCode) return [];
const result = await recentGroupMsgs(groupRoomId(CHANNEL_PREFIX.GUILD, guildCode), count);
const result = await recentGroupMsgs([groupRoomId(CHANNEL_PREFIX.GUILD, guildCode)], count);
return result;
}
@@ -289,7 +299,7 @@ export async function recentLeagueMsgs(guildCode: string, count?: number) {
if(!guildCode) return [];
let myLeague = await GVGLeagueModel.findLeagueByGuild(guildCode);
if(!myLeague) return [];
const result = await recentGroupMsgs(groupRoomId(CHANNEL_PREFIX.LEAGUE, myLeague.leagueCode), count);
const result = await recentGroupMsgs([groupRoomId(CHANNEL_PREFIX.LEAGUE, myLeague.leagueCode)], count);
return result;
}

View File

@@ -1,4 +1,5 @@
import { pinus } from "pinus";
import { uniq } from "underscore";
import { GVG_SERVER_TYPE, SERVER_GROUP_FUN_TYPE } from "../consts";
import { ServerGroupModel } from "../db/ServerGroup";
import { ServerlistModel } from "../db/Serverlist";
@@ -27,6 +28,12 @@ export async function setServerGroup() {
}
export async function getAllGroupOfServer(serverId: number) {
let gvgGroupId = await getGVGGroupIdOfServer(serverId);
let pvpGroupId = await getPVPGroupIdOfServer(serverId);
return uniq([gvgGroupId, pvpGroupId]);
}
// GVG相关查询本小区所在战区
export async function getGVGGroupIdOfServer(serverId: number) {
return await getGroupIdOfServer(serverId, SERVER_GROUP_FUN_TYPE.GVG);

View File

@@ -17,7 +17,7 @@ export const CHANNEL_PREFIX = {
SYS: 'sys',
WORLD: 'world',
GUILD: 'guild',
GVG: 'gvg', // 战区
GVG: 'gvg', // 战区虽然叫gvg但是这个战区应该是包括pvp和3v3功能的
TEAM: 'com_btl_team',
CITY: 'city', // 军团活动诸侯混战按城池分channel
GUILD_AUCTION: 'g_auction', // 军团拍卖

View File

@@ -55,8 +55,8 @@ export default class GroupMessage extends BaseModel {
return result;
}
public static async getMsgs(roomId: string, fromSeqId: number, count: number) {
const result = await GroupMessageModel.find({ roomId, seqId: { $lt: fromSeqId } }).sort({ seqId: -1 }).limit(count).lean();
public static async getMsgs(roomIds: string[], fromSeqId: number, count: number) {
const result = await GroupMessageModel.find({ roomId: { $in: roomIds }, seqId: { $lt: fromSeqId } }).sort({ seqId: -1 }).limit(count).lean();
return result;
}
}