✨ 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
@@ -1,6 +1,6 @@
import { CHANNEL_PREFIX, MSG_SOURCE, getChannelType } from './../../../consts/constModules/chatConst'; import { CHANNEL_PREFIX, MSG_SOURCE, getChannelType } from './../../../consts/constModules/chatConst';
import { Application, BackendSession, HandlerService, } from 'pinus'; 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 { 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 { createAccuseData, createGroupMsg, createPrivateMsg, getPrivateMessages, pushGroupMsgToRoom, pushMsgToRole, updatePrivateMsgReadInfo, recentPrivateChatInfos, recentWorldMsgs, recentSysMsgs, recentGuildMsgs, updatePrivateMsgIsTop, delPrivateMsg, recentServerGroupMsgs, recentLeagueMsgs } from '../../../services/chatService';
import { getSimpleRoleInfo } from '../../../services/roleService'; import { getSimpleRoleInfo } from '../../../services/roleService';
@@ -8,8 +8,9 @@ import { checkTask } from '../../../services/task/taskService';
import { RoleModel } from '../../../db/Role'; import { RoleModel } from '../../../db/Role';
import { getFriendRelationType } from '../../../services/friendService'; import { getFriendRelationType } from '../../../services/friendService';
import { GVGLeagueModel } from '../../../db/GVGLeague'; import { GVGLeagueModel } from '../../../db/GVGLeague';
import { getGVGGroupIdOfServer } from '../../../services/serverService'; import { getAllGroupOfServer } from '../../../services/serverService';
import { getGuildCodeString } from '../../../services/gvg/gvgRecService'; import { getGuildCodeString } from '../../../services/gvg/gvgRecService';
import { GroupMessageType } from '../../../db/GroupMessage';
export default function (app: Application) { export default function (app: Application) {
@@ -36,22 +37,26 @@ export class ChatHandler {
const guildCode = session.get('guildCode'); const guildCode = session.get('guildCode');
const sid = session.get('sid'); const sid = session.get('sid');
let channelId = '', otherInfo = ''; let channelIds: (string|number)[] = [], otherInfo = '';
if (channel === CHANNEL_PREFIX.WORLD) channelId = `${serverId}`; if (channel === CHANNEL_PREFIX.WORLD) channelIds.push(serverId);
if (channel === CHANNEL_PREFIX.GUILD) channelId = guildCode; if (channel === CHANNEL_PREFIX.GUILD) channelIds.push(guildCode);
if (channel === CHANNEL_PREFIX.GVG) { if (channel === CHANNEL_PREFIX.GVG) {
let groupId = await getGVGGroupIdOfServer(serverId); let groupIds = await getAllGroupOfServer(serverId);
channelId = `${groupId}`; groupIds.forEach(groupId => channelIds.push(groupId));
otherInfo = genCode(10);
} }
if (channel == CHANNEL_PREFIX.LEAGUE) { if (channel == CHANNEL_PREFIX.LEAGUE) {
let myLeague = await GVGLeagueModel.findLeagueByGuild(guildCode); let myLeague = await GVGLeagueModel.findLeagueByGuild(guildCode);
if(!myLeague) return resResult(STATUS.GVG_NOT_JOIN_LEAGUE); if(!myLeague) return resResult(STATUS.GVG_NOT_JOIN_LEAGUE);
channelId = myLeague.leagueCode; channelIds.push(myLeague.leagueCode);
otherInfo = getGuildCodeString(myLeague); otherInfo = getGuildCodeString(myLeague);
} }
const msgData = await createGroupMsg(roleId, roleName, channel, channelId, type, MSG_SOURCE.ROLE_SEND_TEXT, content, targetRoleId, targetMsgCode, otherInfo); let msgData: GroupMessageType;
if (!msgData) return resResult(STATUS.WRONG_PARMS); for(let channelId of channelIds) {
await pushGroupMsgToRoom(msgData); 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) }); await checkTask(serverId, roleId, sid, TASK_TYPE.CHAT, { chatType: getChannelType(channel) });
+21 -11
View File
@@ -17,7 +17,7 @@ import { sendMessageToAllWithSuc, sendMessageToCityWithSuc, sendMessageToGuildWi
import { comBtlLvInvalid } from './comBattleService'; import { comBtlLvInvalid } from './comBattleService';
import { gameData } from '../pubUtils/data'; import { gameData } from '../pubUtils/data';
import { RegionModel } from '../db/Region'; import { RegionModel } from '../db/Region';
import { getGVGGroupIdOfServer, getGVGServersByGroupId } from './serverService'; import { getAllGroupOfServer, getGVGGroupIdOfServer, getGVGServersByGroupId } from './serverService';
import { GVGLeagueModel } from '../db/GVGLeague'; import { GVGLeagueModel } from '../db/GVGLeague';
export * from './chatChannelService'; export * from './chatChannelService';
@@ -209,14 +209,23 @@ function sendFromRole(msg: GroupMessageParam) {
* @param {number} [count] 期望获取的消息数 * @param {number} [count] 期望获取的消息数
* @returns * @returns
*/ */
async function recentGroupMsgs(roomId: string, count?: number) { async function recentGroupMsgs(roomIds: string[], count?: number) {
const msgs = await GroupMessageModel.getMsgs(roomId, Infinity, count || CHAT_SYSTEM.RECENT_GROUP_MSGS_CNT); const msgs = await GroupMessageModel.getMsgs(roomIds, Infinity, count || CHAT_SYSTEM.RECENT_GROUP_MSGS_CNT);
const roleIds = msgs const roleIds = msgs
.map(msg => { return sendFromRole(msg) ? msg.roleId : null }) .map(msg => { return sendFromRole(msg) ? msg.roleId : null })
.filter(roleId => !!roleId); .filter(roleId => !!roleId);
const roleInfos = await getSimpleRoleInfos(roleIds); 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 ? const result = roleInfos ?
msgs.map(msg => { filterMsgs.map(msg => {
if (!sendFromRole(msg)) return msg; if (!sendFromRole(msg)) return msg;
for (let roleInfo of roleInfos) { for (let roleInfo of roleInfos) {
if (roleInfo.roleId === msg.roleId) { if (roleInfo.roleId === msg.roleId) {
@@ -224,7 +233,7 @@ async function recentGroupMsgs(roomId: string, count?: number) {
} }
} }
}) })
: msgs; : filterMsgs;
return result.filter(cur => cur) || []; return result.filter(cur => cur) || [];
} }
@@ -236,8 +245,9 @@ async function recentGroupMsgs(roomId: string, count?: number) {
* @returns * @returns
*/ */
export async function recentServerGroupMsgs(serverId: number, count?: number) { export async function recentServerGroupMsgs(serverId: number, count?: number) {
let groupId = await getGVGGroupIdOfServer(serverId); let groupIds = await getAllGroupOfServer(serverId);
const result = await recentGroupMsgs(groupRoomId(CHANNEL_PREFIX.GVG, groupId), count); let roomIds = groupIds.map(groupId => groupRoomId(CHANNEL_PREFIX.GVG, groupId));
const result = await recentGroupMsgs(roomIds, count);
return result; return result;
} }
@@ -249,7 +259,7 @@ export async function recentServerGroupMsgs(serverId: number, count?: number) {
* @returns * @returns
*/ */
export async function recentWorldMsgs(serverId: number, count?: number) { 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; return result;
} }
@@ -261,7 +271,7 @@ export async function recentWorldMsgs(serverId: number, count?: number) {
* @returns * @returns
*/ */
export async function recentSysMsgs(serverId: number, count?: number) { 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; return result;
} }
@@ -274,7 +284,7 @@ export async function recentSysMsgs(serverId: number, count?: number) {
*/ */
export async function recentGuildMsgs(guildCode: string, count?: number) { export async function recentGuildMsgs(guildCode: string, count?: number) {
if(!guildCode) return []; 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; return result;
} }
@@ -289,7 +299,7 @@ export async function recentLeagueMsgs(guildCode: string, count?: number) {
if(!guildCode) return []; if(!guildCode) return [];
let myLeague = await GVGLeagueModel.findLeagueByGuild(guildCode); let myLeague = await GVGLeagueModel.findLeagueByGuild(guildCode);
if(!myLeague) return []; 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; return result;
} }
@@ -1,4 +1,5 @@
import { pinus } from "pinus"; import { pinus } from "pinus";
import { uniq } from "underscore";
import { GVG_SERVER_TYPE, SERVER_GROUP_FUN_TYPE } from "../consts"; import { GVG_SERVER_TYPE, SERVER_GROUP_FUN_TYPE } from "../consts";
import { ServerGroupModel } from "../db/ServerGroup"; import { ServerGroupModel } from "../db/ServerGroup";
import { ServerlistModel } from "../db/Serverlist"; 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相关:查询本小区所在战区 // GVG相关:查询本小区所在战区
export async function getGVGGroupIdOfServer(serverId: number) { export async function getGVGGroupIdOfServer(serverId: number) {
return await getGroupIdOfServer(serverId, SERVER_GROUP_FUN_TYPE.GVG); return await getGroupIdOfServer(serverId, SERVER_GROUP_FUN_TYPE.GVG);
+1 -1
View File
@@ -17,7 +17,7 @@ export const CHANNEL_PREFIX = {
SYS: 'sys', SYS: 'sys',
WORLD: 'world', WORLD: 'world',
GUILD: 'guild', GUILD: 'guild',
GVG: 'gvg', // 战区 GVG: 'gvg', // 战区,虽然叫gvg,但是这个战区应该是包括pvp和3v3功能的
TEAM: 'com_btl_team', TEAM: 'com_btl_team',
CITY: 'city', // 军团活动,诸侯混战,按城池分channel CITY: 'city', // 军团活动,诸侯混战,按城池分channel
GUILD_AUCTION: 'g_auction', // 军团拍卖 GUILD_AUCTION: 'g_auction', // 军团拍卖
+2 -2
View File
@@ -55,8 +55,8 @@ export default class GroupMessage extends BaseModel {
return result; return result;
} }
public static async getMsgs(roomId: string, fromSeqId: number, count: number) { public static async getMsgs(roomIds: string[], fromSeqId: number, count: number) {
const result = await GroupMessageModel.find({ roomId, seqId: { $lt: fromSeqId } }).sort({ seqId: -1 }).limit(count).lean(); const result = await GroupMessageModel.find({ roomId: { $in: roomIds }, seqId: { $lt: fromSeqId } }).sort({ seqId: -1 }).limit(count).lean();
return result; return result;
} }
} }