102 lines
2.3 KiB
Go
102 lines
2.3 KiB
Go
package friend
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/utils"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
func (this *apiComp) AddblackCheck(session comm.IUserSession, req *pb.FriendAddBlackReq) (code pb.ErrorCode) {
|
|
if req.FriendId == "" {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
//加入黑名单
|
|
func (this *apiComp) Addblack(session comm.IUserSession, req *pb.FriendAddBlackReq) (code pb.ErrorCode, data proto.Message) {
|
|
if code = this.AddblackCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
globalCnf := this.moduleFriend.configure.GetGlobalConf()
|
|
if globalCnf == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
|
|
var (
|
|
err error
|
|
self *pb.DBFriend
|
|
target *pb.DBFriend
|
|
Resp *pb.FriendAddBlackResp
|
|
)
|
|
|
|
defer func() {
|
|
Resp = &pb.FriendAddBlackResp{
|
|
FriendId: req.FriendId,
|
|
UserId: session.GetUserId(),
|
|
}
|
|
if err = session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeAddBlack, Resp); err != nil {
|
|
code = pb.ErrorCode_SystemError
|
|
return
|
|
}
|
|
}()
|
|
|
|
self = this.moduleFriend.modelFriend.GetFriend(session.GetUserId())
|
|
if self == nil {
|
|
code = pb.ErrorCode_FriendSelfNoData
|
|
return
|
|
}
|
|
|
|
target = this.moduleFriend.modelFriend.GetFriend(req.FriendId)
|
|
if target == nil {
|
|
code = pb.ErrorCode_FriendTargetNoData
|
|
return
|
|
}
|
|
|
|
//判断目标是否在好友列表里面
|
|
// if _, ok := utils.Find(self.FriendIds, req.FriendId); ok {
|
|
// code = pb.ErrorCode_FriendYet
|
|
// return
|
|
// }
|
|
|
|
//判断目标是否已经在黑名单中
|
|
if _, ok := utils.Find(self.BlackIds, req.FriendId); ok {
|
|
code = pb.ErrorCode_FriendSelfBlackYet
|
|
return
|
|
}
|
|
|
|
// 判断自己是否在对方的黑名单中
|
|
if _, ok := utils.Find(target.BlackIds, self.Uid); ok {
|
|
code = pb.ErrorCode_FriendTargetBlackYet
|
|
return
|
|
}
|
|
|
|
// 判断是否黑名单人数已满
|
|
if len(self.BlackIds) >= int(globalCnf.FriendBlack) {
|
|
code = pb.ErrorCode_FriendBlackMax
|
|
return
|
|
}
|
|
|
|
//将目标加入黑名单
|
|
self.BlackIds = append(self.BlackIds, req.FriendId)
|
|
|
|
// 将目标从好友列表中移除
|
|
friendIds := utils.DeleteString(self.FriendIds, req.FriendId)
|
|
|
|
//更新
|
|
err = this.moduleFriend.modelFriend.Change(self.Uid, map[string]interface{}{
|
|
"blackIds": self.BlackIds,
|
|
"friendIds": friendIds,
|
|
})
|
|
if err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|