Merge branch 'tuoyun' of github.com:OpenIMSDK/Open-IM-Server into tuoyun

# Conflicts:
#	internal/rpc/friend/firend.go
pull/218/head
wangchuxiao 3 years ago
commit 0aefbc2c7d

@ -84,6 +84,18 @@ func (s *friendServer) AddBlacklist(ctx context.Context, req *pbFriend.AddBlackl
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
log.NewInfo(req.CommID.OperationID, "AddBlacklist rpc ok ", req.CommID.FromUserID, req.CommID.ToUserID)
reqAddBlackUserToCache := &pbCache.AddBlackUserToCacheReq{UserID: req.CommID.FromUserID, BlackUserID: req.CommID.ToUserID, OperationID: req.CommID.OperationID}
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName)
cacheClient := pbCache.NewCacheClient(etcdConn)
cacheResp, err := cacheClient.AddBlackUserToCache(context.Background(), reqAddBlackUserToCache)
if err != nil {
log.NewError(req.CommID.OperationID, "AddBlackUserToCache rpc call failed ", err.Error())
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: 500, ErrMsg: "AddBlackUserToCache rpc call failed"}}, nil
}
if cacheResp.CommonResp.ErrCode != 0 {
log.NewError(req.CommID.OperationID, "AddBlackUserToCache rpc logic call failed ", cacheResp.String())
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}}, nil
}
chat.BlackAddedNotification(req)
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{}}, nil
}
@ -362,6 +374,18 @@ func (s *friendServer) RemoveBlacklist(ctx context.Context, req *pbFriend.Remove
}
log.NewInfo(req.CommID.OperationID, "rpc RemoveBlacklist ok ")
reqReduceBlackUserFromCache := &pbCache.ReduceBlackUserFromCacheReq{UserID: req.CommID.FromUserID, BlackUserID: req.CommID.ToUserID, OperationID: req.CommID.OperationID}
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName)
cacheClient := pbCache.NewCacheClient(etcdConn)
cacheResp, err := cacheClient.ReduceBlackUserFromCache(context.Background(), reqReduceBlackUserFromCache)
if err != nil {
log.NewError(req.CommID.OperationID, "ReduceBlackUserFromCache rpc call failed ", err.Error())
return &pbFriend.RemoveBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: 500, ErrMsg: "ReduceBlackUserFromCache rpc call failed"}}, nil
}
if cacheResp.CommonResp.ErrCode != 0 {
log.NewError(req.CommID.OperationID, "ReduceBlackUserFromCache rpc logic call failed ", cacheResp.String())
return &pbFriend.RemoveBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}}, nil
}
chat.BlackDeletedNotification(req)
return &pbFriend.RemoveBlacklistResp{CommonResp: &pbFriend.CommonResp{}}, nil
}

@ -6,9 +6,9 @@ import (
"Open_IM/pkg/common/db"
"Open_IM/pkg/common/log"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
cacheRpc "Open_IM/pkg/proto/cache"
pbChat "Open_IM/pkg/proto/chat"
pbConversation "Open_IM/pkg/proto/conversation"
rpc "Open_IM/pkg/proto/friend"
pbGroup "Open_IM/pkg/proto/group"
sdk_ws "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils"
@ -48,36 +48,38 @@ func userRelationshipVerification(data *pbChat.SendMsgReq) (bool, int32, string)
return true, 0, ""
}
log.NewDebug(data.OperationID, config.Config.MessageVerify.FriendVerify)
req := &rpc.IsInBlackListReq{CommID: &rpc.CommID{}}
req.CommID.OperationID = data.OperationID
req.CommID.OpUserID = data.MsgData.RecvID
req.CommID.FromUserID = data.MsgData.RecvID
req.CommID.ToUserID = data.MsgData.SendID
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
client := rpc.NewFriendClient(etcdConn)
reply, err := client.IsInBlackList(context.Background(), req)
reqGetBlackIDListFromCache := &cacheRpc.GetBlackIDListFromCacheReq{UserID: data.MsgData.RecvID, OperationID: data.OperationID}
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName)
cacheClient := cacheRpc.NewCacheClient(etcdConn)
cacheResp, err := cacheClient.GetBlackIDListFromCache(context.Background(), reqGetBlackIDListFromCache)
if err != nil {
log.NewDebug(data.OperationID, "IsInBlackListReq rpc failed, ", req.String(), err.Error())
} else if reply.Response == true {
log.NewDebug(data.OperationID, "IsInBlackListReq ", req.String())
return false, 600, "in black list"
log.NewError(data.OperationID, "GetBlackIDListFromCache rpc call failed ", err.Error())
} else {
if cacheResp.CommonResp.ErrCode != 0 {
log.NewError(data.OperationID, "GetBlackIDListFromCache rpc logic call failed ", cacheResp.String())
} else {
if utils.IsContain(data.MsgData.SendID, cacheResp.UserIDList) {
return false, 600, "in black list"
}
}
}
log.NewDebug(data.OperationID, config.Config.MessageVerify.FriendVerify)
if config.Config.MessageVerify.FriendVerify {
friendReq := &rpc.IsFriendReq{CommID: &rpc.CommID{}}
friendReq.CommID.OperationID = data.OperationID
friendReq.CommID.OpUserID = data.MsgData.RecvID
friendReq.CommID.FromUserID = data.MsgData.RecvID
friendReq.CommID.ToUserID = data.MsgData.SendID
friendReply, err := client.IsFriend(context.Background(), friendReq)
reqGetFriendIDListFromCache := &cacheRpc.GetFriendIDListFromCacheReq{UserID: data.MsgData.RecvID, OperationID: data.OperationID}
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName)
cacheClient := cacheRpc.NewCacheClient(etcdConn)
cacheResp, err := cacheClient.GetFriendIDListFromCache(context.Background(), reqGetFriendIDListFromCache)
if err != nil {
log.NewDebug(data.OperationID, "IsFriendReq rpc failed, ", req.String(), err.Error())
return true, 0, ""
} else if friendReply.Response == false {
log.NewDebug(data.OperationID, "not friend ", req.String())
return friendReply.Response, 601, "not friend"
log.NewError(data.OperationID, "GetFriendIDListFromCache rpc call failed ", err.Error())
} else {
if cacheResp.CommonResp.ErrCode != 0 {
log.NewError(data.OperationID, "GetFriendIDListFromCache rpc logic call failed ", cacheResp.String())
} else {
if !utils.IsContain(data.MsgData.SendID, cacheResp.UserIDList) {
return false, 601, "not friend"
}
}
}
log.NewDebug(data.OperationID, config.Config.MessageVerify.FriendVerify, friendReply.Response)
return true, 0, ""
} else {
return true, 0, ""

Loading…
Cancel
Save