86 lines
2.3 KiB
Go
86 lines
2.3 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) (errdata *pb.ErrorData) {
|
|
if req.FriendId == "" {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
this.module.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) (errdata *pb.ErrorData) {
|
|
if errdata = this.DelCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
|
|
uid := session.GetUserId()
|
|
self := this.module.modelFriend.GetFriend(uid)
|
|
if self == nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_FriendSelfNoData,
|
|
Title: pb.ErrorCode_FriendSelfNoData.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
// 从好友列表中删除
|
|
selfFriendIds := utils.Deletex(self.FriendIds, req.FriendId)
|
|
|
|
if err := this.module.modelFriend.Change(self.Uid, map[string]interface{}{
|
|
"friendIds": selfFriendIds,
|
|
}); err != nil {
|
|
this.module.Error("删除好友",
|
|
log.Field{Key: "uid", Value: uid},
|
|
log.Field{Key: "params", Value: req.String()},
|
|
log.Field{Key: "err", Value: err.Error()},
|
|
)
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_FriendApplyError,
|
|
Title: pb.ErrorCode_FriendApplyError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
target := this.module.modelFriend.GetFriend(req.FriendId)
|
|
if target == nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_FriendNotSelf,
|
|
Title: pb.ErrorCode_FriendNotSelf.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
// 将自己从对方好友列表中移除
|
|
targetFriendIds := utils.DeleteString(target.FriendIds, uid)
|
|
|
|
if err := this.module.modelFriend.Change(req.FriendId, map[string]interface{}{
|
|
"friendIds": targetFriendIds,
|
|
}); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_FriendApplyError,
|
|
Title: pb.ErrorCode_FriendApplyError.ToString(),
|
|
}
|
|
this.module.Error("删除好友",
|
|
log.Field{Key: "uid", Value: uid},
|
|
log.Field{Key: "params", Value: req.FriendId},
|
|
log.Field{Key: "err", Value: err.Error()},
|
|
)
|
|
return
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), FriendSubTypeDel, &pb.FriendDelResp{FriendId: req.FriendId, UserId: self.Uid})
|
|
|
|
return
|
|
}
|