110 lines
2.9 KiB
Go
110 lines
2.9 KiB
Go
package chat
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.ChatGetListReq) (errdata *pb.ErrorData) {
|
|
if req.Channel == pb.ChatChannel_CrossServer && req.ChannelId == 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
///获取本服聊天消息记录
|
|
func (this *apiComp) GetList(session comm.IUserSession, req *pb.ChatGetListReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
err error
|
|
result *pb.DBUserExpand
|
|
list []*pb.DBChat
|
|
)
|
|
|
|
if code = this.GetListCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
switch req.Channel {
|
|
case pb.ChatChannel_World:
|
|
if list, err = this.module.modelChat.getChatQueue(req.Channel, session.GetServiecTag(), "", 0); err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
data = &pb.ErrorData{
|
|
Title: code.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
break
|
|
case pb.ChatChannel_Union:
|
|
if list, err = this.module.modelChat.getChatQueue(req.Channel, session.GetServiecTag(), req.UnionId, 0); err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
data = &pb.ErrorData{
|
|
Title: code.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
break
|
|
case pb.ChatChannel_Private:
|
|
if list, err = this.module.modelChat.queryUserMsg(session.GetUserId()); err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
data = &pb.ErrorData{
|
|
Title: code.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
break
|
|
case pb.ChatChannel_CrossServer:
|
|
if result, err = this.module.ModuleUser.GetUserExpand(session.GetUserId()); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
code = pb.ErrorCode_DBError
|
|
data = &pb.ErrorData{
|
|
Title: code.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if req.ChannelId != result.Chatchannel {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
data = &pb.ErrorData{
|
|
Title: code.ToString(),
|
|
Message: fmt.Sprintf("req.ChannelId:%d != result.Chatchannel:%d", req.ChannelId, result.Chatchannel),
|
|
}
|
|
return
|
|
}
|
|
if list, err = this.module.modelChat.getChatQueue(req.Channel, session.GetServiecTag(), "", req.ChannelId); err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
data = &pb.ErrorData{
|
|
Title: code.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
break
|
|
case pb.ChatChannel_System:
|
|
if list, err = this.module.modelChat.getChatQueue(req.Channel, session.GetServiecTag(), "", 0); err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
data = &pb.ErrorData{
|
|
Title: code.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
break
|
|
default:
|
|
|
|
this.module.Errorf("不存在的聊天频道类型channel:%d ", req.Channel)
|
|
code = pb.ErrorCode_ReqParameterError
|
|
data = &pb.ErrorData{
|
|
Title: code.ToString(),
|
|
Message: fmt.Sprintf("不存在的聊天频道类型 channel:%d ", req.Channel),
|
|
}
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "getlist", &pb.ChatGetListResp{Chats: list})
|
|
return
|
|
}
|