75 lines
1.6 KiB
Go
75 lines
1.6 KiB
Go
package friend
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/utils"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
func (this *apiComp) RefuseCheck(session comm.IUserSession, req *pb.FriendRefuseReq) (code pb.ErrorCode) {
|
|
if len(req.FriendIds) == 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
//单个/批量拒绝
|
|
func (this *apiComp) Refuse(session comm.IUserSession, req *pb.FriendRefuseReq) (code pb.ErrorCode, data proto.Message) {
|
|
if code = this.RefuseCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
//将申请人从申请列表中删除
|
|
var (
|
|
self *pb.DBFriend
|
|
Resp *pb.FriendRefuseResp
|
|
optNum int32
|
|
)
|
|
defer func() {
|
|
Resp = &pb.FriendRefuseResp{
|
|
Num: optNum,
|
|
}
|
|
|
|
err := session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeRefuse, Resp)
|
|
if err != nil {
|
|
code = pb.ErrorCode_SystemError
|
|
return
|
|
}
|
|
}()
|
|
|
|
//获取玩家自己好友数据
|
|
self = this.moduleFriend.modelFriend.GetFriend(session.GetUserId())
|
|
if self == nil {
|
|
code = pb.ErrorCode_FriendSelfNoData
|
|
return
|
|
}
|
|
|
|
//拒绝的Ids
|
|
refuseIds := []string{}
|
|
for _, friendId := range req.FriendIds {
|
|
if _, ok := utils.Find(self.ApplyIds, friendId); ok {
|
|
refuseIds = append(refuseIds, friendId)
|
|
}
|
|
}
|
|
|
|
//将申请人从申请列表中删除
|
|
for _, userId := range refuseIds {
|
|
self.ApplyIds = utils.DeleteString(self.ApplyIds, userId)
|
|
optNum++
|
|
}
|
|
//更新
|
|
if optNum > 0 {
|
|
err := this.moduleFriend.modelFriend.Change(self.Uid, map[string]interface{}{
|
|
"applyIds": self.ApplyIds,
|
|
})
|
|
if err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|