67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
package friend
|
|
|
|
import (
|
|
"context"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/utils"
|
|
)
|
|
|
|
//加入黑名单
|
|
func (this *ApiComp) Addblack(ctx context.Context, session comm.IUserSession, req *pb.FriendBlackAddReq) (err error) {
|
|
var (
|
|
code pb.ErrorCode
|
|
self *pb.DB_FriendData
|
|
target *pb.DB_FriendData
|
|
rsp *pb.FriendBlackAddRsp
|
|
blackNumMax = 50 //TODO 从配置中读取
|
|
)
|
|
|
|
defer func() {
|
|
if code == pb.ErrorCode_Success {
|
|
rsp = &pb.FriendBlackAddRsp{
|
|
FriendId: req.FriendId,
|
|
UserId: session.GetUserId(),
|
|
}
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), Friend_SubType_AddBlack, code, rsp)
|
|
}()
|
|
|
|
err = this.module.model_friend.GetObj(session.GetUserId(), self)
|
|
if self == nil || err != nil {
|
|
code = pb.ErrorCode_FriendSelfNoData
|
|
return
|
|
}
|
|
|
|
err = this.module.model_friend.GetObj(req.FriendId, target)
|
|
if target == nil || err != nil {
|
|
code = pb.ErrorCode_FriendTargetNoData
|
|
return
|
|
}
|
|
|
|
//判断目标是否在好友列表里面
|
|
if _, ok := utils.Find(self.FriendIds, req.FriendId); ok {
|
|
code = pb.ErrorCode_FriendSelfBlackYet
|
|
return
|
|
}
|
|
|
|
// 判断自己是否在对方的黑名单中
|
|
if _, ok := utils.Find(target.BlackIds, self.UserId); ok {
|
|
code = pb.ErrorCode_FriendTargetBlackYet
|
|
return
|
|
}
|
|
|
|
// 判断是否黑名单人数已满
|
|
if len(self.BlackIds) >= blackNumMax {
|
|
code = pb.ErrorCode_FriendBlackMax
|
|
return
|
|
}
|
|
|
|
//将目标加入黑名单
|
|
self.BlackIds = append(self.BlackIds, req.FriendId)
|
|
|
|
//更新黑名单
|
|
this.module.model_friend.SetObj(self.UserId, self, false)
|
|
return nil
|
|
}
|