go_dreamfactory/modules/chat/api_spansend.go
2022-07-20 14:01:59 +08:00

53 lines
1.4 KiB
Go

package chat
import (
"fmt"
"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
userexpand *pb.DBUserExpand
)
if userexpand, err = this.module.modelChat.GetUserExpand(session.GetUserId()); err != nil {
code = pb.ErrorCode_DBError
return
}
msg = &pb.DBChat{
Id: primitive.NewObjectID().Hex(),
Channel: req.Channel,
Suid: session.GetUserId(),
AreaId: userexpand.Chatchannel,
Headid: user.Avatar,
Content: req.Content,
Ctime: time.Now().Unix(),
}
group := this.module.configure.GetServiecTagGroup(session.GetServiecTag())
switch msg.Channel {
case pb.ChatChannel_CrossServer:
if err = this.module.modelChat.addChatMsg(fmt.Sprintf("%s:%d--%d", crosschatkey, group, userexpand.Chatchannel), this.module.configure.GetChannelRecordMax(), msg); err != nil {
code = pb.ErrorCode_DBError
return
}
this.module.PushToUsers(group, userexpand.Chatchannel, msg)
break
}
session.SendMsg(string(this.module.GetType()), "send", &pb.ChatSendResp{})
return
}