go_dreamfactory/modules/friend/api_cross_getrelation.go
2023-04-14 12:21:58 +08:00

57 lines
1.4 KiB
Go

package friend
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
"go_dreamfactory/utils"
)
// 获取好友关系
func (this *apiComp) GetRelationCheck(session comm.IUserSession, req *pb.FriendGetRelationReq) (code pb.ErrorCode) {
if req.TargetUid == "" {
code = pb.ErrorCode_ReqParameterError
this.moduleFriend.Error("参数错误", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "params", Value: req.String()})
}
return
}
func (this *apiComp) GetRelation(session comm.IUserSession, req *pb.FriendGetRelationReq) (code pb.ErrorCode, data *pb.ErrorData) {
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
}