go_dreamfactory/modules/chat/api_spansend.go
2022-07-19 18:09:45 +08:00

48 lines
1.0 KiB
Go

package chat
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
"google.golang.org/protobuf/proto"
)
//参数校验
func (this *apiComp) SpanSendCheck(session comm.IUserSession, req *pb.ChatSpanSendReq) (code pb.ErrorCode) {
return
}
///跨越服务消息请求
func (this *apiComp) SpanSend(session comm.IUserSession, req *pb.ChatSpanSendReq) (code pb.ErrorCode, data proto.Message) {
var (
err error
msg *pb.DBChat
user *pb.DBUser
)
msg = &pb.DBChat{
Id: primitive.NewObjectID().Hex(),
Channel: req.Channel,
Suid: session.GetUserId(),
Headid: user.Avatar,
Content: req.Content,
Ctime: time.Now().Unix(),
}
if err = this.module.modelChat.AddChatMsg(msg); err != nil {
code = pb.ErrorCode_DBError
return
}
session.SendMsg(string(this.module.GetType()), "send", &pb.ChatSendResp{})
switch msg.Channel {
case pb.ChatChannel_CrossServer:
this.module.PushAllWorld(msg)
break
case pb.ChatChannel_System:
this.module.PushAllWorld(msg)
break
}
return
}