聊天:加入玩家发起的群聊和测试用例
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import { GroupMessageType } from './../../../db/GroupMessage';
|
||||
import { Application, ChannelService, FrontendSession, RemoterClass, pinus } from 'pinus';
|
||||
import { Application, ChannelService } from 'pinus';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { STATUS } from '../../../consts';
|
||||
import { ON_ADD_CHANNEL_ROUTE, ON_GROUP_MSG_ROUTE, STATUS } from '../../../consts';
|
||||
import { PrivateMessageType } from '../../../db/PrivateMessage';
|
||||
import { addUserToChannel } from '../../../services/roleService';
|
||||
import { ChannelUser } from '../../../domain/ChannelUser';
|
||||
|
||||
export default function (app: Application) {
|
||||
return new ChatRemote(app);
|
||||
@@ -40,15 +42,13 @@ export class ChatRemote {
|
||||
public async addWorldChannel(roleId: string, serverId: number, sid: string, flag: boolean = true) {
|
||||
const name = `world${serverId}`;
|
||||
let channel = this.channelService.getChannel(name, flag);
|
||||
if (!channel) return;
|
||||
channel.add(roleId, sid);
|
||||
let param = {
|
||||
roleId
|
||||
};
|
||||
channel.pushMessage('onWorldAdd', resResult(STATUS.SUCCESS, param));
|
||||
|
||||
if (!!channel) {
|
||||
channel.add(roleId, sid);
|
||||
}
|
||||
|
||||
return this.getWorldChannel(name);
|
||||
}
|
||||
|
||||
@@ -86,10 +86,8 @@ export class ChatRemote {
|
||||
|
||||
let channel = this.channelService.getChannel(name, false);
|
||||
// leave channel
|
||||
if (!!channel) {
|
||||
channel.leave(roleId, sid);
|
||||
}
|
||||
|
||||
if (!channel) return;
|
||||
channel.leave(roleId, sid);
|
||||
let param = {
|
||||
roleId
|
||||
};
|
||||
@@ -120,7 +118,10 @@ export class ChatRemote {
|
||||
* @memberof ChatRemote
|
||||
*/
|
||||
public async addChannel(channelName: string, roleId: string, sid: string) {
|
||||
|
||||
let channel = this.channelService.getChannel(channelName, true);
|
||||
if (!channel) return;
|
||||
addUserToChannel(channel, new ChannelUser(roleId, sid));
|
||||
channel.pushMessage(ON_ADD_CHANNEL_ROUTE, resResult(STATUS.SUCCESS, { roleId, channelName }));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,7 +132,15 @@ export class ChatRemote {
|
||||
* @memberof ChatRemote
|
||||
*/
|
||||
public async leaveChannel(channelName: string, roleId: string, sid: string) {
|
||||
|
||||
let channel = this.channelService.getChannel(channelName, false);
|
||||
// leave channel
|
||||
if (!channel) return;
|
||||
channel.leave(roleId, sid);
|
||||
let param = {
|
||||
roleId,
|
||||
channelName
|
||||
};
|
||||
channel.pushMessage('onLeave', resResult(STATUS.SUCCESS, param));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,8 +148,10 @@ export class ChatRemote {
|
||||
* @param {Partial<GroupMessageType>} msg
|
||||
* @memberof ChatRemote
|
||||
*/
|
||||
public async sendGroupMsg(msg: Partial<GroupMessageType>) {
|
||||
|
||||
public async sendGroupMsg(roomId: string, msg: Partial<GroupMessageType>) {
|
||||
let channel = this.channelService.getChannel(roomId, false);
|
||||
if (!channel) return;
|
||||
channel.pushMessage(ON_GROUP_MSG_ROUTE, resResult(STATUS.SUCCESS, msg));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,5 +162,4 @@ export class ChatRemote {
|
||||
public async sendPrivateMsg(msg: Partial<PrivateMessageType>) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user