go_dreamfactory/modules/chat/api_sendcross.go
2022-09-15 15:56:39 +08:00

105 lines
3.1 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) SendCrossCheck(session comm.IUserSession, req *pb.ChatSendCrossReq) (code pb.ErrorCode) {
if (req.Channel == pb.ChatChannel_Union && req.TargetId == "") || (req.Channel == pb.ChatChannel_Private && req.TargetId == "") {
code = pb.ErrorCode_ReqParameterError
}
return
}
///消息发送请求
func (this *apiComp) SendCross(session comm.IUserSession, req *pb.ChatSendCrossReq) (code pb.ErrorCode, data proto.Message) {
var (
err error
// max int32
msg *pb.DBChat
userexpand *pb.DBUserExpand
max_chat int32
)
if code = this.SendCrossCheck(session, req); code != pb.ErrorCode_Success {
return
}
msg = &pb.DBChat{
Id: primitive.NewObjectID().Hex(),
Channel: req.Channel,
Suid: session.GetUserId(),
Slv: req.Ulv,
Uname: req.Uname,
Avatar: req.Avatar,
Stag: session.GetServiecTag(),
Content: req.Content,
Ctime: time.Now().Unix(),
}
// if max, err = this.module.configure.GetChannelRecordMax(); err != nil {
// code = pb.ErrorCode_ConfigNoFound
// return
// }
if max_chat, err = this.module.configure.GetChannelRecordMax(); err != nil {
code = pb.ErrorCode_ConfigNoFound
return
}
switch msg.Channel {
// case pb.ChatChannel_World:
// if err = this.module.modelChat.addChatMsg(fmt.Sprintf("%s-%s", worldchatkey, session.GetServiecTag()), int64(max), msg); err != nil {
// code = pb.ErrorCode_DBError
// return
// }
// if err = this.module.PushWorld(msg); err != nil {
// code = pb.ErrorCode_DBError
// return
// }
// //随机任务
// this.module.ModuleRtask.SendToRtask(session, comm.Rtype62, 1)
// break
// case pb.ChatChannel_Union:
// msg.UnionId = req.TargetId
// if err = this.module.modelChat.addChatMsg(fmt.Sprintf("%s:%s", unionchatkey, req.TargetId), int64(max_chat), msg); err != nil {
// code = pb.ErrorCode_DBError
// return
// }
// if err = this.module.PushUnion(req.TargetId, msg); err != nil {
// code = pb.ErrorCode_DBError
// return
// }
// break
// case pb.ChatChannel_Private:
// msg.Ruid = req.TargetId
// if err = this.module.PushUser(msg); err != nil {
// code = pb.ErrorCode_DBError
// return
// }
// session.SendMsg(string(this.module.GetType()), "message", &pb.ChatMessagePush{Chat: msg})
// break
case pb.ChatChannel_CrossServer:
if userexpand, err = this.module.ModuleUser.GetUserExpand(session.GetUserId()); err != nil {
code = pb.ErrorCode_DBError
return
}
msg.ChannelId = userexpand.Chatchannel //指定频道
if err = this.module.modelChat.addChatMsg(fmt.Sprintf("%s-%d", crosschatkey, userexpand.Chatchannel), int64(max_chat), msg); err != nil {
code = pb.ErrorCode_DBError
return
}
this.module.PushToUsers(userexpand.Chatchannel, msg)
break
default:
code = pb.ErrorCode_ReqParameterError
this.module.Errorf("getlist no support channel:%d ", req.Channel)
return
}
session.SendMsg(string(this.module.GetType()), "sendcross", &pb.ChatSendCrossResp{Issucc: true})
return
}