聊天:初始化时获取群消息

This commit is contained in:
liangtongchuan
2021-03-10 16:42:03 +08:00
parent 99a3098bea
commit 24f297b480
4 changed files with 54 additions and 8 deletions

View File

@@ -10,7 +10,7 @@ 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, 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 { crc32 } from 'crc';
import { HeroType } from '../db/Hero';
@@ -34,7 +34,7 @@ export function privateRoomId(roleId: string, targetRoleId: string) {
* @param {string} channelId
* @returns
*/
export function groupRoomId(channel: string, channelId: string) {
export function groupRoomId(channel: string, channelId: string | number) {
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) {
const roomId = groupRoomId(CHANNEL_PREFIX.SYS, `${serverId}`);
const roomId = groupRoomId(CHANNEL_PREFIX.SYS, serverId);
await addRoleToChannel(roomId, roleId, sid);
}
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);
}
@@ -194,12 +194,12 @@ async function leaveChannel(roomId: string, roleId: string, sid: string) {
}
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);
}
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);
}
@@ -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 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 roomId = groupRoomId(CHANNEL_PREFIX.SYS, `${serverId}`);
const roomId = groupRoomId(CHANNEL_PREFIX.SYS, serverId);
await pushGroupMsgToRoom(roomId, msgData);
}
@@ -325,3 +325,23 @@ export async function recentPrivateChatInfos(roleId: string, roleName: string) {
});
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;
}