104 lines
2.6 KiB
Go
104 lines
2.6 KiB
Go
package chat
|
|
|
|
import (
|
|
"context"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/base"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
|
|
"google.golang.org/protobuf/types/known/anypb"
|
|
)
|
|
|
|
/*
|
|
模块名:论坛
|
|
描述:处理跨服社交论坛相关业务
|
|
开发:李伟
|
|
*/
|
|
func NewModule() core.IModule {
|
|
m := new(Chat)
|
|
return m
|
|
}
|
|
|
|
type Chat struct {
|
|
modules.ModuleBase
|
|
service base.IRPCXService //rpc服务对象 通过这个对象可以发布服务和调用其他服务的接口
|
|
api_comp *apiComp
|
|
configure *configureComp
|
|
modelChat *modelChatComp
|
|
}
|
|
|
|
//模块名
|
|
func (this *Chat) GetType() core.M_Modules {
|
|
return comm.ModuleEquipment
|
|
}
|
|
|
|
//模块初始化接口 注册用户创建角色事件
|
|
func (this *Chat) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
|
err = this.ModuleBase.Init(service, module, options)
|
|
this.service = service.(base.IRPCXService)
|
|
return
|
|
}
|
|
|
|
//装备组件
|
|
func (this *Chat) OnInstallComp() {
|
|
this.ModuleBase.OnInstallComp()
|
|
this.api_comp = this.RegisterComp(new(apiComp)).(*apiComp)
|
|
this.modelChat = this.RegisterComp(new(modelChatComp)).(*modelChatComp)
|
|
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
|
}
|
|
|
|
//Push--------------------------------------------------------------------------------------------------------------
|
|
//推送消息到世界
|
|
func (this *Chat) PushWorld(msg *pb.DBChat) {
|
|
var (
|
|
err error
|
|
reply *pb.RPCMessageReply
|
|
)
|
|
reply = &pb.RPCMessageReply{}
|
|
data, _ := anypb.New(msg)
|
|
if err = this.service.RpcBroadcast(context.Background(), comm.Service_Gateway, string(comm.Rpc_GatewaySendRadioMsg), pb.UserMessage{
|
|
MainType: string(this.GetType()),
|
|
SubType: "push",
|
|
Data: data,
|
|
}, reply); err != nil {
|
|
this.Errorf("err:%v", err)
|
|
}
|
|
}
|
|
|
|
//推送消息到工会
|
|
func (this *Chat) PushUnion(msg *pb.DBChat) {
|
|
|
|
}
|
|
|
|
//推送消息到用户
|
|
func (this *Chat) PushUser(msg *pb.DBChat) {
|
|
if session, ok := this.GetUserSession(msg.Ruid); ok {
|
|
session.SendMsg(string(this.GetType()), "push", msg)
|
|
if err := session.Push(); err != nil {
|
|
this.Errorf("err:%v", err)
|
|
}
|
|
return
|
|
} else {
|
|
this.modelChat.SaveUserMsg(msg)
|
|
}
|
|
}
|
|
|
|
//全集群推送
|
|
func (this *Chat) PushAllWorld(msg *pb.DBChat) {
|
|
var (
|
|
err error
|
|
reply *pb.RPCMessageReply
|
|
)
|
|
reply = &pb.RPCMessageReply{}
|
|
data, _ := anypb.New(msg)
|
|
if err = this.service.ClusterBroadcast(context.Background(), comm.Service_Gateway, string(comm.Rpc_GatewaySendRadioMsg), pb.UserMessage{
|
|
MainType: string(this.GetType()),
|
|
SubType: "push",
|
|
Data: data,
|
|
}, reply); err != nil {
|
|
this.Errorf("err:%v", err)
|
|
}
|
|
}
|