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 } }