go_dreamfactory/modules/chat/api_spansend.go
2022-07-20 17:56:09 +08:00

61 lines
1.6 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
group int32
max_chat int32
)
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(),
}
if group, err = this.module.configure.GetServiecTagGroup(session.GetServiecTag()); err != nil {
code = pb.ErrorCode_ConfigNoFound
return
}
if max_chat, err = this.module.configure.GetChannelRecordMax(); err != nil {
return
}
switch msg.Channel {
case pb.ChatChannel_CrossServer:
if err = this.module.modelChat.addChatMsg(fmt.Sprintf("%s:%d--%d", crosschatkey, group, userexpand.Chatchannel), max_chat, msg); err != nil {
code = pb.ErrorCode_DBError
return
}
this.module.PushToUsers(group, userexpand.Chatchannel, msg)
break
}
session.SendMsg(string(this.module.GetType()), "spansend", &pb.ChatSendResp{})
return
}