From 906cb85fc3acdee94ed286cd5cd3ffc28284fc83 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Fri, 25 Aug 2023 12:02:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A5=BD=E5=8F=8B=E7=94=B3=E8=AF=B7=20?= =?UTF-8?q?=E5=A6=82=E6=9E=9C=E5=9C=A8=E5=A5=BD=E5=8F=8B=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E4=B8=AD=E5=B0=B1=E5=88=A0=E9=99=A4=E7=94=B3=E8=AF=B7=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E4=B8=AD=E7=9A=84=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/friend/api_cross_applylist.go | 37 +++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/modules/friend/api_cross_applylist.go b/modules/friend/api_cross_applylist.go index 6cf29b05b..d5afbb7ac 100644 --- a/modules/friend/api_cross_applylist.go +++ b/modules/friend/api_cross_applylist.go @@ -13,8 +13,10 @@ func (this *apiComp) ApplyListCheck(session comm.IUserSession, req *pb.FriendApp func (this *apiComp) ApplyList(session comm.IUserSession, req *pb.FriendApplyListReq) (errdata *pb.ErrorData) { var ( - self *pb.DBFriend - list []*pb.FriendBase + self *pb.DBFriend + list []*pb.FriendBase + bChange bool + bUpdate bool ) self = this.module.modelFriend.GetFriend(session.GetUserId()) @@ -27,9 +29,34 @@ func (this *apiComp) ApplyList(session comm.IUserSession, req *pb.FriendApplyLis } for _, userId := range self.ApplyIds { - base := this.setDefaultFriendUserBaseInfo(userId) - if base != nil { - list = append(list, base) + bChange = false + // 如果在还好有列表就删除 + for pos, v := range self.FriendIds { + if v == userId { // 找到了 + self.FriendIds = append(self.FriendIds[:pos], self.FriendIds[pos+1:]...) + bChange = true + bUpdate = true + break + } + } + if !bChange { + base := this.setDefaultFriendUserBaseInfo(userId) + if base != nil { + list = append(list, base) + } + } + } + + if bUpdate { // 更新数据 + if err := this.module.modelFriend.Change(self.Uid, map[string]interface{}{ + "friendIds": self.FriendIds, + }); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Title: pb.ErrorCode_DBError.ToString(), + Message: err.Error(), + } + return } }