92 lines
2.2 KiB
Go
92 lines
2.2 KiB
Go
package friend
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/utils"
|
|
)
|
|
|
|
func (this *apiComp) AddblackCheck(session comm.IUserSession, req *pb.FriendBlackAddReq) (chk map[string]interface{}, code comm.ErrorCode) {
|
|
chk = make(map[string]interface{})
|
|
var (
|
|
err error
|
|
blackNumMax = 50 //TODO 从配置中读取
|
|
)
|
|
self := &pb.DBFriend{UId: session.GetUserId()}
|
|
target := &pb.DBFriend{UId: req.FriendId}
|
|
|
|
err = this.module.modelFriend.Get(session.GetUserId(), self)
|
|
if self == nil || err != nil {
|
|
code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfNoData}
|
|
return
|
|
}
|
|
|
|
err = this.module.modelFriend.Get(req.FriendId, target)
|
|
if target == nil || err != nil {
|
|
code = comm.ErrorCode{Code: pb.ErrorCode_FriendTargetNoData}
|
|
return
|
|
}
|
|
|
|
//判断目标是否在好友列表里面
|
|
if _, ok := utils.Find(self.FriendIds, req.FriendId); ok {
|
|
code = comm.ErrorCode{Code: pb.ErrorCode_FriendYet}
|
|
return
|
|
}
|
|
|
|
//判断目标是否已经在黑名单中
|
|
if _, ok := utils.Find(self.BlackIds, req.FriendId); ok {
|
|
code = comm.ErrorCode{Code: pb.ErrorCode_FriendSelfBlackYet}
|
|
return
|
|
}
|
|
|
|
// 判断自己是否在对方的黑名单中
|
|
if _, ok := utils.Find(target.BlackIds, self.UId); ok {
|
|
code = comm.ErrorCode{Code: pb.ErrorCode_FriendTargetBlackYet}
|
|
return
|
|
}
|
|
|
|
// 判断是否黑名单人数已满
|
|
if len(self.BlackIds) >= blackNumMax {
|
|
code = comm.ErrorCode{Code: pb.ErrorCode_FriendBlackMax}
|
|
return
|
|
}
|
|
|
|
chk["self"] = self
|
|
chk["target"] = target
|
|
|
|
return
|
|
}
|
|
|
|
//加入黑名单
|
|
func (this *apiComp) Addblack(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendBlackAddReq) (code pb.ErrorCode) {
|
|
var (
|
|
self *pb.DBFriend
|
|
rsp *pb.FriendBlackAddRsp
|
|
)
|
|
|
|
defer func() {
|
|
rsp = &pb.FriendBlackAddRsp{
|
|
FriendId: req.FriendId,
|
|
UserId: session.GetUserId(),
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), FriendSubTypeAddBlack, rsp)
|
|
}()
|
|
|
|
if v, ok := chk["self"]; ok {
|
|
self = v.(*pb.DBFriend)
|
|
//将目标加入黑名单
|
|
self.BlackIds = append(self.BlackIds, req.FriendId)
|
|
|
|
//更新黑名单
|
|
err := this.module.modelFriend.Change(self.UId, map[string]interface{}{
|
|
"blackIds": self.BlackIds,
|
|
})
|
|
if err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|