From d45f5fdc8aa25bc43d4574aad00b9c16530edf71 Mon Sep 17 00:00:00 2001 From: wh_zcy Date: Thu, 18 Aug 2022 20:09:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=82=B9=E8=B5=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/friend/api_addblack.go | 8 ++++++-- modules/friend/api_blacklist.go | 1 + modules/friend/api_list.go | 11 +++++------ modules/friend/api_randlist.go | 22 +++++++++++++++++----- modules/friend/api_zan.go | 26 +++++++++++++------------- 5 files changed, 42 insertions(+), 26 deletions(-) diff --git a/modules/friend/api_addblack.go b/modules/friend/api_addblack.go index f6e8dcdc2..06c0613cf 100644 --- a/modules/friend/api_addblack.go +++ b/modules/friend/api_addblack.go @@ -78,9 +78,13 @@ func (this *apiComp) Addblack(session comm.IUserSession, req *pb.FriendAddBlackR //将目标加入黑名单 self.BlackIds = append(self.BlackIds, req.FriendId) - //更新黑名单 + // 将目标从好友列表中移除 + friendIds := utils.DeleteString(self.FriendIds, req.FriendId) + + //更新 err = this.moduleFriend.modelFriend.Change(self.Uid, map[string]interface{}{ - "blackIds": self.BlackIds, + "blackIds": self.BlackIds, + "friendIds": friendIds, }) if err != nil { code = pb.ErrorCode_DBError diff --git a/modules/friend/api_blacklist.go b/modules/friend/api_blacklist.go index 8cac9b6b8..cf8bb00ae 100644 --- a/modules/friend/api_blacklist.go +++ b/modules/friend/api_blacklist.go @@ -46,6 +46,7 @@ func (this *apiComp) Blacklist(session comm.IUserSession, req *pb.FriendBlackLis list = append(list, &pb.FriendBase{ UserId: userId, NickName: user.Name, + Level: user.Lv, }) } diff --git a/modules/friend/api_list.go b/modules/friend/api_list.go index c241ba97c..45be5e6b9 100644 --- a/modules/friend/api_list.go +++ b/modules/friend/api_list.go @@ -62,13 +62,12 @@ func (this *apiComp) List(session comm.IUserSession, req *pb.FriendListReq) (cod base.OfflineTime = user.Offlinetime //离线时间 } - // 判断是否在自己的申请列表中 - if _, ok := utils.Findx(self.ApplyIds, userId); ok { - base.IsApplied = true - } - // 判断是否已点赞 - if _, ok := utils.Findx(self.ZanIds, userId); ok { + target := this.moduleFriend.modelFriend.GetFriend(userId) + if target == nil { + continue + } + if _, ok := utils.Findx(target.ZanIds, self.Uid); ok { base.IsZaned = true } diff --git a/modules/friend/api_randlist.go b/modules/friend/api_randlist.go index 2a3319f45..74f029ce5 100644 --- a/modules/friend/api_randlist.go +++ b/modules/friend/api_randlist.go @@ -37,18 +37,30 @@ func (this *apiComp) Randlist(session comm.IUserSession, req *pb.FriendRandlistR if _, ok := utils.Findx(self.FriendIds, v.Uid); ok { continue } - if _, ok := utils.Findx(self.ApplyIds, v.Uid); ok { - continue - } + // if _, ok := utils.Findx(self.ApplyIds, v.Uid); ok { + // continue + // } user := this.moduleFriend.ModuleUser.GetUser(v.Uid) if user == nil { continue } - userList = append(userList, &pb.FriendBase{ + + base := &pb.FriendBase{ UserId: user.Uid, NickName: user.Name, Level: user.Lv, - }) + } + + // 判断是否在自己的申请列表中 + target := this.moduleFriend.modelFriend.GetFriend(v.Uid) + if target == nil { + continue + } + if _, ok := utils.Findx(target.ApplyIds, self.Uid); ok { + base.IsApplied = true + } + + userList = append(userList, base) } rsp := &pb.FriendRandlistResp{ diff --git a/modules/friend/api_zan.go b/modules/friend/api_zan.go index f4c145c2c..630396200 100644 --- a/modules/friend/api_zan.go +++ b/modules/friend/api_zan.go @@ -38,8 +38,7 @@ func (this *apiComp) Zan(session comm.IUserSession, req *pb.FriendZanReq) (code } var ( - pointTotal int32 //友情值累加 - optIds []string //本次操作的有效id + pointTotal int32 //友情值累加 ) // 是否已给好友点赞 for _, v := range req.FriendIds { @@ -48,18 +47,19 @@ func (this *apiComp) Zan(session comm.IUserSession, req *pb.FriendZanReq) (code code = pb.ErrorCode_FriendSelfNoData return } - if _, ok := utils.Find(target.ZanIds, selfId); !ok { - optIds = append(optIds, v) - pointTotal += 1 - } - } - //设置被点赞玩家 - if err = this.moduleFriend.modelFriend.Change(target.GetUid(), map[string]interface{}{ - "zanIds": optIds, - }); err != nil { - code = pb.ErrorCode_DBError - return + if _, ok := utils.Find(target.ZanIds, selfId); !ok { + + pointTotal += 1 + target.ZanIds = append(target.ZanIds, selfId) + //设置被点赞玩家 + if err = this.moduleFriend.modelFriend.Change(target.GetUid(), map[string]interface{}{ + "zanIds": target.ZanIds, + }); err != nil { + code = pb.ErrorCode_DBError + return + } + } } //设置友情值