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) SendCheck(session comm.IUserSession, req *pb.ChatSendReq) (code pb.ErrorCode) { return } ///消息发送请求 func (this *apiComp) Send(session comm.IUserSession, req *pb.ChatSendReq) (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(), Ruid: req.TargetId, 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_World: this.module.PushWorld(msg) break case pb.ChatChannel_Union: this.module.PushUnion(msg) break case pb.ChatChannel_Private: this.module.PushUser(msg) break } return }