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
+21 -11
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;
}