聊天:增加用户信息等字段
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { PrivateChatRec } from './../db/ChatInfo';
|
||||
import { RoleModel } from './../db/Role';
|
||||
import { RoleModel, RoleUpdate } from './../db/Role';
|
||||
import { GroupMessageModel } from './../db/GroupMessage';
|
||||
import { CounterModel } from './../db/Counter';
|
||||
import { STATUS } from './../consts/statusCode';
|
||||
@@ -12,6 +12,7 @@ import { getRoleOnlineInfo } from './redisService';
|
||||
import { ChatInfoModel } from '../db/ChatInfo';
|
||||
import { channelServer } from './chatChannelService';
|
||||
import { AccuseRecModel, AccueseParam } from '../db/AccuseRec';
|
||||
import { getSimpleRoleInfo, getSimpleRoleInfos } from './roleService';
|
||||
|
||||
export * from './chatChannelService';
|
||||
export * from './sysChatService';
|
||||
@@ -127,7 +128,8 @@ export async function pushMsgToRole(msg: PrivateMessageType | GroupMessageType)
|
||||
const targetRoleId = msg.targetRoleId!;
|
||||
const { sid } = await getRoleOnlineInfo(targetRoleId);
|
||||
if (sid) {
|
||||
pinus.app.get('channelService').pushMessageByUids(ON_PRIVATE_MSG_ROUTE, resResult(STATUS.SUCCESS, msg), [{uid: targetRoleId, sid}]);
|
||||
const roleInfo = await getSimpleRoleInfo(msg.roleId);
|
||||
pinus.app.get('channelService').pushMessageByUids(ON_PRIVATE_MSG_ROUTE, resResult(STATUS.SUCCESS, { ...msg, roleInfo }), [{ uid: targetRoleId, sid }]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +143,8 @@ export async function pushGroupMsgToRoom(msg: GroupMessageType) {
|
||||
if (!msg) return;
|
||||
const roomId = msg.roomId!;
|
||||
const channelSid = await channelServer(roomId);
|
||||
await pinus.app.rpc.chat.chatRemote.sendGroupMsg.toServer(channelSid, roomId, msg);
|
||||
const roleInfo = await getSimpleRoleInfo(msg.roleId);
|
||||
await pinus.app.rpc.chat.chatRemote.sendGroupMsg.toServer(channelSid, roomId, { ...msg, roleInfo });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,6 +161,10 @@ export async function getPrivateMessages(roleId: string, targetRoleId: string, f
|
||||
return result;
|
||||
}
|
||||
|
||||
function sendFromRole(msg: GroupMessageParam) {
|
||||
return msg.source === MSG_SOURCE.ROLE_SEND_TEXT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 最近群聊消息
|
||||
* @param {string} roomId 群聊房间标识
|
||||
@@ -165,7 +172,20 @@ export async function getPrivateMessages(roleId: string, targetRoleId: string, f
|
||||
* @returns
|
||||
*/
|
||||
async function recentGroupMsgs(roomId: string, count?: number) {
|
||||
const result = await GroupMessageModel.getMsgs(roomId, Infinity, count || RECENT_GROUP_MSGS_CNT);
|
||||
const msgs = await GroupMessageModel.getMsgs(roomId, Infinity, count || RECENT_GROUP_MSGS_CNT);
|
||||
const roleIds = msgs
|
||||
.map(msg => { return sendFromRole(msg) ? msg.roleId : null })
|
||||
.filter(roleId => !!roleId);
|
||||
const roleInfos = await getSimpleRoleInfos(roleIds);
|
||||
const result = roleInfos ?
|
||||
msgs.map(msg => {
|
||||
for (let roleInfo of roleInfos) {
|
||||
if (roleInfo.roleId === msg.roleId) {
|
||||
return { ...msg, roleInfo };
|
||||
}
|
||||
}
|
||||
})
|
||||
: msgs;
|
||||
return result || [];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user