59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package friend
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/utils"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
// 获取好友关系
|
|
func (this *apiComp) GetRelationCheck(session comm.IUserSession, req *pb.FriendGetRelationReq) (code pb.ErrorCode) {
|
|
if req.TargetUid == "" {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
this.moduleFriend.Error("参数错误", log.Fields{"uid": session.GetUserId(), "params": req})
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) GetRelation(session comm.IUserSession, req *pb.FriendGetRelationReq) (code pb.ErrorCode, data proto.Message) {
|
|
if code = this.GetRelationCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
self := this.moduleFriend.modelFriend.GetFriend(session.GetUserId())
|
|
if self == nil {
|
|
code = pb.ErrorCode_FriendSelfNoData
|
|
return
|
|
}
|
|
|
|
target := this.moduleFriend.modelFriend.GetFriend(req.TargetUid)
|
|
if target == nil {
|
|
code = pb.ErrorCode_FriendTargetNoData
|
|
return
|
|
}
|
|
var status bool
|
|
|
|
// 已申请目标玩家
|
|
if _, ok := utils.Findx(target.ApplyIds, self.Uid); ok {
|
|
status = true
|
|
}
|
|
|
|
//目标玩家已是好友
|
|
if _, ok := utils.Findx(self.FriendIds, req.TargetUid); ok {
|
|
status = true
|
|
}
|
|
|
|
resp := &pb.FriendGetRelationResp{
|
|
TargetUid: req.TargetUid,
|
|
Status: status,
|
|
}
|
|
if err := session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeRelation, resp); err != nil {
|
|
code = pb.ErrorCode_SystemError
|
|
return
|
|
}
|
|
return
|
|
}
|