73 lines
2.0 KiB
Go
73 lines
2.0 KiB
Go
package friend
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/utils"
|
|
)
|
|
|
|
//删除好友
|
|
func (this *apiComp) DelCheck(session comm.IUserSession, req *pb.FriendDelReq) (code pb.ErrorCode) {
|
|
if req.FriendId == "" {
|
|
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) Del(session comm.IUserSession, req *pb.FriendDelReq) (code pb.ErrorCode, data *pb.ErrorData) {
|
|
if code = this.DelCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
uid := session.GetUserId()
|
|
self := this.moduleFriend.modelFriend.GetFriend(uid)
|
|
if self == nil {
|
|
code = pb.ErrorCode_FriendSelfNoData
|
|
return
|
|
}
|
|
|
|
// 从好友列表中删除
|
|
selfFriendIds := utils.Deletex(self.FriendIds, req.FriendId)
|
|
|
|
if err := this.moduleFriend.modelFriend.Change(self.Uid, map[string]interface{}{
|
|
"friendIds": selfFriendIds,
|
|
}); err != nil {
|
|
this.moduleFriend.Error("删除好友",
|
|
log.Field{Key: "uid", Value: uid},
|
|
log.Field{Key: "params", Value: req.String()},
|
|
log.Field{Key: "err", Value: err.Error()},
|
|
)
|
|
code = pb.ErrorCode_FriendApplyError
|
|
return
|
|
}
|
|
|
|
target := this.moduleFriend.modelFriend.GetFriend(req.FriendId)
|
|
if target == nil {
|
|
code = pb.ErrorCode_FriendNotSelf
|
|
return
|
|
}
|
|
|
|
// 将自己从对方好友列表中移除
|
|
targetFriendIds := utils.DeleteString(target.FriendIds, uid)
|
|
|
|
if err := this.moduleFriend.modelFriend.Change(req.FriendId, map[string]interface{}{
|
|
"friendIds": targetFriendIds,
|
|
}); err != nil {
|
|
code = pb.ErrorCode_FriendApplyError
|
|
this.moduleFriend.Error("删除好友",
|
|
log.Field{Key: "uid", Value: uid},
|
|
log.Field{Key: "params", Value: req.FriendId},
|
|
log.Field{Key: "err", Value: err.Error()},
|
|
)
|
|
return
|
|
}
|
|
|
|
if err := session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeDel, &pb.FriendDelResp{FriendId: req.FriendId, UserId: self.Uid}); err != nil {
|
|
code = pb.ErrorCode_SystemError
|
|
}
|
|
|
|
return
|
|
}
|