聊天:初始化时获取群消息
This commit is contained in:
@@ -19,7 +19,7 @@ import { GuildModel } from '../../../db/Guild';
|
|||||||
import { gameData } from '../../../pubUtils/data';
|
import { gameData } from '../../../pubUtils/data';
|
||||||
|
|
||||||
import { getMails } from '../../../services/mailService';
|
import { getMails } from '../../../services/mailService';
|
||||||
import { addRoleToGuildChannel, addRoleToSysChannel, addRoleToWorldChannel, leaveGuildChannel, leaveSysChannel, leaveWorldChannel, recentPrivateChatInfos } from '../../../services/chatService';
|
import { addRoleToGuildChannel, addRoleToSysChannel, addRoleToWorldChannel, leaveGuildChannel, leaveSysChannel, leaveWorldChannel, recentGuildMsgs, recentPrivateChatInfos, recentSysMsgs, recentWorldMsgs } from '../../../services/chatService';
|
||||||
import { reportOneOnline } from '../../../services/timeTaskService';
|
import { reportOneOnline } from '../../../services/timeTaskService';
|
||||||
export default function (app: Application) {
|
export default function (app: Application) {
|
||||||
return new EntryHandler(app);
|
return new EntryHandler(app);
|
||||||
@@ -113,6 +113,8 @@ export class EntryHandler {
|
|||||||
if (recentPrivateChats) {
|
if (recentPrivateChats) {
|
||||||
role['recentPrivateChats'] = recentPrivateChats;
|
role['recentPrivateChats'] = recentPrivateChats;
|
||||||
}
|
}
|
||||||
|
role['worldMsgs'] = await recentWorldMsgs(role.serverId);
|
||||||
|
role['sysMsgs'] = await recentSysMsgs(role.serverId);
|
||||||
|
|
||||||
if(role.hasGuild) {
|
if(role.hasGuild) {
|
||||||
let userGuild = await UserGuildModel.getMyGuild(role.roleId, USER_GUILD_SELECT.ENTRY );
|
let userGuild = await UserGuildModel.getMyGuild(role.roleId, USER_GUILD_SELECT.ENTRY );
|
||||||
@@ -120,6 +122,7 @@ export class EntryHandler {
|
|||||||
let guild = await GuildModel.findGuild(userGuild.guildCode, role.serverId, GUILD_SELECT.ENTRY);
|
let guild = await GuildModel.findGuild(userGuild.guildCode, role.serverId, GUILD_SELECT.ENTRY);
|
||||||
if(guild) {
|
if(guild) {
|
||||||
addRoleToGuildChannel(role.roleId, self.app.get('serverId'), userGuild.guildCode);
|
addRoleToGuildChannel(role.roleId, self.app.get('serverId'), userGuild.guildCode);
|
||||||
|
role['guildMsgs'] = await recentGuildMsgs(userGuild.guildCode);
|
||||||
role['guildAuth'] = userGuild.auth;
|
role['guildAuth'] = userGuild.auth;
|
||||||
role['guildCode'] = userGuild.guildCode;
|
role['guildCode'] = userGuild.guildCode;
|
||||||
let {lv: guildLv, memberCnt} = guild;
|
let {lv: guildLv, memberCnt} = guild;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { PrivateMessageModel, PrivateMessageParam, PrivateMessageType } from './
|
|||||||
import { GroupMessageParam, GroupMessageType } from '../db/GroupMessage';
|
import { GroupMessageParam, GroupMessageType } from '../db/GroupMessage';
|
||||||
import { genCode, resResult } from '../pubUtils/util';
|
import { genCode, resResult } from '../pubUtils/util';
|
||||||
import { pinus } from 'pinus';
|
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, RECENT_PRIVATE_CHATS_CNT, MAX_PRIVATE_MSGS } 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, RECENT_GROUP_MSGS_CNT } from '../consts';
|
||||||
import { addRedisChannel, getRoleOnlineInfo, redisChannelServer } from './redisService';
|
import { addRedisChannel, getRoleOnlineInfo, redisChannelServer } from './redisService';
|
||||||
import { crc32 } from 'crc';
|
import { crc32 } from 'crc';
|
||||||
import { HeroType } from '../db/Hero';
|
import { HeroType } from '../db/Hero';
|
||||||
@@ -34,7 +34,7 @@ export function privateRoomId(roleId: string, targetRoleId: string) {
|
|||||||
* @param {string} channelId
|
* @param {string} channelId
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export function groupRoomId(channel: string, channelId: string) {
|
export function groupRoomId(channel: string, channelId: string | number) {
|
||||||
return `${channel}_${channelId}`;
|
return `${channel}_${channelId}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,12 +174,12 @@ async function addRoleToChannel(roomId: string, roleId: string, sid: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function addRoleToSysChannel(roleId: string, sid: string, serverId: number) {
|
export async function addRoleToSysChannel(roleId: string, sid: string, serverId: number) {
|
||||||
const roomId = groupRoomId(CHANNEL_PREFIX.SYS, `${serverId}`);
|
const roomId = groupRoomId(CHANNEL_PREFIX.SYS, serverId);
|
||||||
await addRoleToChannel(roomId, roleId, sid);
|
await addRoleToChannel(roomId, roleId, sid);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function addRoleToWorldChannel(roleId: string, sid: string, serverId: number) {
|
export async function addRoleToWorldChannel(roleId: string, sid: string, serverId: number) {
|
||||||
const roomId = groupRoomId(CHANNEL_PREFIX.WORLD, `${serverId}`);
|
const roomId = groupRoomId(CHANNEL_PREFIX.WORLD, serverId);
|
||||||
await addRoleToChannel(roomId, roleId, sid);
|
await addRoleToChannel(roomId, roleId, sid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,12 +194,12 @@ async function leaveChannel(roomId: string, roleId: string, sid: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function leaveSysChannel(roleId: string, sid: string, serverId: number) {
|
export async function leaveSysChannel(roleId: string, sid: string, serverId: number) {
|
||||||
const roomId = groupRoomId(CHANNEL_PREFIX.SYS, `${serverId}`);
|
const roomId = groupRoomId(CHANNEL_PREFIX.SYS, serverId);
|
||||||
await leaveChannel(roomId, roleId, sid);
|
await leaveChannel(roomId, roleId, sid);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function leaveWorldChannel(roleId: string, sid: string, serverId: number) {
|
export async function leaveWorldChannel(roleId: string, sid: string, serverId: number) {
|
||||||
const roomId = groupRoomId(CHANNEL_PREFIX.WORLD, `${serverId}`);
|
const roomId = groupRoomId(CHANNEL_PREFIX.WORLD, serverId);
|
||||||
await leaveChannel(roomId, roleId, sid);
|
await leaveChannel(roomId, roleId, sid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,7 +230,7 @@ async function pushNormalHeroInfoBySource(roleId: string, roleName: string, serv
|
|||||||
const hero = pick(heroInfo, ['hName', 'hid', 'seqId', 'quality', 'star', 'starStage', 'colorStar', 'colorStarStage']);
|
const hero = pick(heroInfo, ['hName', 'hid', 'seqId', 'quality', 'star', 'starStage', 'colorStar', 'colorStarStage']);
|
||||||
const content = JSON.stringify({ roleId, roleName, hero });
|
const content = JSON.stringify({ roleId, roleName, hero });
|
||||||
const msgData = await createGroupMsg(roleId, roleName, CHANNEL_PREFIX.SYS, `${serverId}`, MSG_TYPE.RICH_TEXT, source, content, null, null);
|
const msgData = await createGroupMsg(roleId, roleName, CHANNEL_PREFIX.SYS, `${serverId}`, MSG_TYPE.RICH_TEXT, source, content, null, null);
|
||||||
const roomId = groupRoomId(CHANNEL_PREFIX.SYS, `${serverId}`);
|
const roomId = groupRoomId(CHANNEL_PREFIX.SYS, serverId);
|
||||||
await pushGroupMsgToRoom(roomId, msgData);
|
await pushGroupMsgToRoom(roomId, msgData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,3 +325,23 @@ export async function recentPrivateChatInfos(roleId: string, roleName: string) {
|
|||||||
});
|
});
|
||||||
return chatInfos;
|
return chatInfos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function recentGroupMsgs(roomId: string, count?: number) {
|
||||||
|
const result = await GroupMessageModel.getMsgs(roomId, Infinity, count || RECENT_GROUP_MSGS_CNT);
|
||||||
|
return result || [];
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function recentWorldMsgs(serverId: number, count?: number) {
|
||||||
|
const result = await recentGroupMsgs(groupRoomId(CHANNEL_PREFIX.WORLD, serverId), count);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function recentSysMsgs(serverId: number, count?: number) {
|
||||||
|
const result = await recentGroupMsgs(groupRoomId(CHANNEL_PREFIX.SYS, serverId), count);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function recentGuildMsgs(guildCode: string, count?: number) {
|
||||||
|
const result = await recentGroupMsgs(groupRoomId(CHANNEL_PREFIX.GUILD, guildCode), count);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -173,6 +173,28 @@ describe('聊天测试', function() {
|
|||||||
checkChatInfos(roleInfoT);
|
checkChatInfos(roleInfoT);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('最近群聊的消息', function() {
|
||||||
|
function checkMsgs(msgs, roleName) {
|
||||||
|
expect(msgs).to.be.an('array');
|
||||||
|
if (msgs.length === 0) {
|
||||||
|
console.warn(`用户${roleName}缺少群消息`);
|
||||||
|
}
|
||||||
|
for (let msg of msgs) {
|
||||||
|
expect(msg.roleId).to.be.a('string');
|
||||||
|
expect(msg.roleName).to.be.a('string');
|
||||||
|
expect(msg.content).to.be.a('string');
|
||||||
|
expect(msg.roomId).to.be.a('string');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function checkAllGroupMsgs(roleInfo) {
|
||||||
|
checkMsgs(roleInfo.sysMsgs, roleInfo.roleName);
|
||||||
|
checkMsgs(roleInfo.worldMsgs, roleInfo.roleName);
|
||||||
|
checkMsgs(roleInfo.guildMsgs, roleInfo.roleName);
|
||||||
|
}
|
||||||
|
checkAllGroupMsgs(roleInfo);
|
||||||
|
checkAllGroupMsgs(roleInfoT);
|
||||||
|
});
|
||||||
|
|
||||||
it('测试系统频道橙将合成消息', function(done) {
|
it('测试系统频道橙将合成消息', function(done) {
|
||||||
let msgReceiveCnt = 0;
|
let msgReceiveCnt = 0;
|
||||||
pinusClientT.on(ON_GROUP_MSG_ROUTE, (res) => {
|
pinusClientT.on(ON_GROUP_MSG_ROUTE, (res) => {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
export const MSG_CODE_LEN = 8;
|
export const MSG_CODE_LEN = 8;
|
||||||
export const RECENT_PRIVATE_CHATS_CNT = 20;
|
export const RECENT_PRIVATE_CHATS_CNT = 20;
|
||||||
|
export const RECENT_GROUP_MSGS_CNT = 10;
|
||||||
export const MAX_PRIVATE_MSGS = 99;
|
export const MAX_PRIVATE_MSGS = 99;
|
||||||
|
|
||||||
export const MSG_STATUS = {
|
export const MSG_STATUS = {
|
||||||
|
|||||||
Reference in New Issue
Block a user