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) 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(), Headid: user.Avatar, Content: req.Content, Ctime: time.Now().Unix(), } switch msg.Channel { case pb.ChatChannel_World: if err = this.module.modelChat.addChatMsg(worldchatkey, this.module.configure.GetChannelRecordMax(), msg); err != nil { code = pb.ErrorCode_DBError return } this.module.PushWorld(msg) break case pb.ChatChannel_Union: msg.UnionId = req.TargetId if err = this.module.modelChat.addChatMsg(fmt.Sprintf("%s:%s", unionchatkey, req.TargetId), this.module.configure.GetChannelRecordMax(), msg); err != nil { code = pb.ErrorCode_DBError return } this.module.PushUnion(msg) break case pb.ChatChannel_Private: msg.Ruid = req.TargetId this.module.PushUser(msg) break } session.SendMsg(string(this.module.GetType()), "send", &pb.ChatSendResp{}) return }