75 lines
1.8 KiB
Go
75 lines
1.8 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) 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
|
|
max int32
|
|
msg *pb.DBChat
|
|
user *pb.DBUser
|
|
max_chat int32
|
|
)
|
|
|
|
if user = this.module.ModuleUser.GetUser(session.GetUserId()); user == nil {
|
|
this.module.Errorf("GetUser is nill")
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
|
|
msg = &pb.DBChat{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Channel: req.Channel,
|
|
Suid: session.GetUserId(),
|
|
Headid: user.Avatar,
|
|
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(worldchatkey, max, 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), max_chat, 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
|
|
}
|