You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/internal/rpc/friend/friend.go

739 lines
36 KiB

3 years ago
package friend
import (
3 years ago
chat "Open_IM/internal/rpc/msg"
3 years ago
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
3 years ago
"Open_IM/pkg/common/db"
3 years ago
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
2 years ago
rocksCache "Open_IM/pkg/common/db/rocks_cache"
3 years ago
"Open_IM/pkg/common/log"
2 years ago
promePkg "Open_IM/pkg/common/prometheus"
3 years ago
"Open_IM/pkg/common/token_verify"
3 years ago
cp "Open_IM/pkg/common/utils"
3 years ago
"Open_IM/pkg/grpc-etcdv3/getcdv3"
3 years ago
pbCache "Open_IM/pkg/proto/cache"
3 years ago
pbFriend "Open_IM/pkg/proto/friend"
3 years ago
sdkws "Open_IM/pkg/proto/sdk_ws"
3 years ago
"Open_IM/pkg/utils"
"context"
2 years ago
"errors"
"fmt"
2 years ago
"gorm.io/gorm"
3 years ago
"net"
"strconv"
"strings"
3 years ago
"time"
3 years ago
2 years ago
grpcPrometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
3 years ago
"google.golang.org/grpc"
3 years ago
)
type friendServer struct {
rpcPort int
rpcRegisterName string
etcdSchema string
etcdAddr []string
}
func NewFriendServer(port int) *friendServer {
3 years ago
log.NewPrivateLog(constant.LogFileName)
3 years ago
return &friendServer{
rpcPort: port,
rpcRegisterName: config.Config.RpcRegisterName.OpenImFriendName,
etcdSchema: config.Config.Etcd.EtcdSchema,
etcdAddr: config.Config.Etcd.EtcdAddr,
}
}
func (s *friendServer) Run() {
3 years ago
log.NewInfo("0", "friendServer run...")
3 years ago
3 years ago
listenIP := ""
if config.Config.ListenIP == "" {
listenIP = "0.0.0.0"
} else {
listenIP = config.Config.ListenIP
}
address := listenIP + ":" + strconv.Itoa(s.rpcPort)
3 years ago
//listener network
3 years ago
listener, err := net.Listen("tcp", address)
3 years ago
if err != nil {
3 years ago
panic("listening err:" + err.Error() + s.rpcRegisterName)
3 years ago
}
3 years ago
log.NewInfo("0", "listen ok ", address)
3 years ago
defer listener.Close()
//grpc server
2 years ago
var grpcOpts []grpc.ServerOption
if config.Config.Prometheus.Enable {
2 years ago
promePkg.NewGrpcRequestCounter()
promePkg.NewGrpcRequestFailedCounter()
promePkg.NewGrpcRequestSuccessCounter()
2 years ago
grpcOpts = append(grpcOpts, []grpc.ServerOption{
2 years ago
// grpc.UnaryInterceptor(promePkg.UnaryServerInterceptorProme),
2 years ago
grpc.StreamInterceptor(grpcPrometheus.StreamServerInterceptor),
grpc.UnaryInterceptor(grpcPrometheus.UnaryServerInterceptor),
}...)
2 years ago
}
srv := grpc.NewServer(grpcOpts...)
3 years ago
defer srv.GracefulStop()
//User friend related services register to etcd
pbFriend.RegisterFriendServer(srv, s)
2 years ago
rpcRegisterIP := config.Config.RpcRegisterIP
3 years ago
if config.Config.RpcRegisterIP == "" {
rpcRegisterIP, err = utils.GetLocalIP()
if err != nil {
log.Error("", "GetLocalIP failed ", err.Error())
}
}
3 years ago
log.NewInfo("", "rpcRegisterIP", rpcRegisterIP)
3 years ago
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), rpcRegisterIP, s.rpcPort, s.rpcRegisterName, 10)
3 years ago
if err != nil {
3 years ago
log.NewError("0", "RegisterEtcd failed ", err.Error(), s.etcdSchema, strings.Join(s.etcdAddr, ","), rpcRegisterIP, s.rpcPort, s.rpcRegisterName)
panic(utils.Wrap(err, "register friend module rpc to etcd err"))
3 years ago
}
err = srv.Serve(listener)
if err != nil {
3 years ago
log.NewError("0", "Serve failed ", err.Error(), listener)
3 years ago
return
}
}
3 years ago
func (s *friendServer) AddBlacklist(ctx context.Context, req *pbFriend.AddBlacklistReq) (*pbFriend.AddBlacklistResp, error) {
3 years ago
log.NewInfo(req.CommID.OperationID, "AddBlacklist args ", req.String())
2 years ago
ok := token_verify.CheckAccess(ctx, req.CommID.OpUserID, req.CommID.FromUserID)
3 years ago
if !ok {
2 years ago
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(ctx, constant.ErrNoPermission, "accress")}, nil
3 years ago
}
3 years ago
black := db.Black{OwnerUserID: req.CommID.FromUserID, BlockUserID: req.CommID.ToUserID, OperatorUserID: req.CommID.OpUserID}
2 years ago
err := imdb.InsertInToUserBlackList(ctx, black)
3 years ago
if err != nil {
2 years ago
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(ctx, constant.ErrDatabase, err.Error())}, nil
3 years ago
}
2 years ago
etcdConn := getcdv3.GetDefaultConn(ctx, config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.CommID.OperationID)
if etcdConn == nil {
2 years ago
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(ctx, constant.ErrInternalServer, "conn is nil")}, nil
}
cacheClient := pbCache.NewCacheClient(etcdConn)
2 years ago
cacheResp, err := cacheClient.DelBlackIDListFromCache(ctx, &pbCache.DelBlackIDListFromCacheReq{UserID: req.CommID.FromUserID, OperationID: req.CommID.OperationID})
if err != nil {
2 years ago
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(ctx, constant.ErrInternalServer, err.Error())}, nil
}
if cacheResp.CommonResp.ErrCode != 0 {
2 years ago
err = errors.New(fmt.Sprintf("call DelBlackIDListFromCache rpc failed code is %d, err is %s, args is %s", cacheResp.CommonResp.ErrCode, cacheResp.CommonResp.ErrMsg, req.CommID.FromUserID))
2 years ago
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(ctx, constant.ErrInternalServer, err.Error())}, nil
}
3 years ago
chat.BlackAddedNotification(req)
2 years ago
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(ctx, constant.ErrNone, "")}, nil
3 years ago
}
3 years ago
func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq) (*pbFriend.AddFriendResp, error) {
3 years ago
log.NewInfo(req.CommID.OperationID, "AddFriend args ", req.String())
ok := token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID)
if !ok {
3 years ago
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
return &pbFriend.AddFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
3 years ago
}
callbackResp := callbackBeforeAddFriend(req)
if callbackResp.ErrCode != 0 {
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendSingleMsg resp: ", callbackResp)
}
if callbackResp.ActionCode != constant.ActionAllow {
if callbackResp.ErrCode == 0 {
callbackResp.ErrCode = 201
}
log.NewDebug(req.CommID.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendSingleMsg result", "end rpc and return", callbackResp)
return &pbFriend.AddFriendResp{CommonResp: &pbFriend.CommonResp{
ErrCode: int32(callbackResp.ErrCode),
ErrMsg: callbackResp.ErrMsg,
}}, nil
}
2 years ago
var isSend = true
userIDList, err := rocksCache.GetFriendIDListFromCache(req.CommID.ToUserID)
if err != nil {
log.NewError(req.CommID.OperationID, "GetFriendIDListFromCache failed ", err.Error(), req.CommID.ToUserID)
return &pbFriend.AddFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil
}
userIDList2, err := rocksCache.GetFriendIDListFromCache(req.CommID.FromUserID)
if err != nil {
log.NewError(req.CommID.OperationID, "GetUserByUserID failed ", err.Error(), req.CommID.FromUserID)
return &pbFriend.AddFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil
}
2 years ago
log.NewDebug(req.CommID.OperationID, "toUserID", userIDList, "fromUserID", userIDList2)
2 years ago
for _, v := range userIDList {
if v == req.CommID.FromUserID {
for _, v2 := range userIDList2 {
if v2 == req.CommID.ToUserID {
isSend = false
2 years ago
break
2 years ago
}
}
2 years ago
break
2 years ago
}
3 years ago
}
2 years ago
//Cannot add non-existent users
if isSend {
if _, err := imdb.GetUserByUserID(req.CommID.ToUserID); err != nil {
log.NewError(req.CommID.OperationID, "GetUserByUserID failed ", err.Error(), req.CommID.ToUserID)
return &pbFriend.AddFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
friendRequest := db.FriendRequest{
HandleResult: 0, ReqMsg: req.ReqMsg, CreateTime: time.Now()}
utils.CopyStructFields(&friendRequest, req.CommID)
// {openIM001 openIM002 0 test add friend 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC }]
log.NewDebug(req.CommID.OperationID, "UpdateFriendApplication args ", friendRequest)
//err := imdb.InsertFriendApplication(&friendRequest)
err := imdb.InsertFriendApplication(&friendRequest,
map[string]interface{}{"handle_result": 0, "req_msg": friendRequest.ReqMsg, "create_time": friendRequest.CreateTime,
"handler_user_id": "", "handle_msg": "", "handle_time": utils.UnixSecondToTime(0), "ex": ""})
if err != nil {
log.NewError(req.CommID.OperationID, "UpdateFriendApplication failed ", err.Error(), friendRequest)
return &pbFriend.AddFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
chat.FriendApplicationNotification(req)
3 years ago
}
2 years ago
//Establish a latest relationship in the friend request table
3 years ago
3 years ago
return &pbFriend.AddFriendResp{CommonResp: &pbFriend.CommonResp{}}, nil
3 years ago
}
func (s *friendServer) ImportFriend(ctx context.Context, req *pbFriend.ImportFriendReq) (*pbFriend.ImportFriendResp, error) {
3 years ago
log.NewInfo(req.OperationID, "ImportFriend args ", req.String())
3 years ago
resp := pbFriend.ImportFriendResp{CommonResp: &pbFriend.CommonResp{}}
3 years ago
var c pbFriend.CommonResp
if !utils.IsContain(req.OpUserID, config.Config.Manager.AppManagerUid) {
3 years ago
log.NewError(req.OperationID, "not authorized", req.OpUserID, config.Config.Manager.AppManagerUid)
3 years ago
c.ErrCode = constant.ErrAccess.ErrCode
c.ErrMsg = constant.ErrAccess.ErrMsg
3 years ago
for _, v := range req.FriendUserIDList {
resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: v, Result: -1})
}
resp.CommonResp = &c
return &resp, nil
3 years ago
}
3 years ago
if _, err := imdb.GetUserByUserID(req.FromUserID); err != nil {
3 years ago
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.FromUserID)
3 years ago
c.ErrCode = constant.ErrDB.ErrCode
3 years ago
c.ErrMsg = "this user not exists,cant not add friend"
3 years ago
for _, v := range req.FriendUserIDList {
resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: v, Result: -1})
}
resp.CommonResp = &c
return &resp, nil
3 years ago
}
for _, v := range req.FriendUserIDList {
3 years ago
log.NewDebug(req.OperationID, "FriendUserIDList ", v)
3 years ago
if _, fErr := imdb.GetUserByUserID(v); fErr != nil {
3 years ago
log.NewError(req.OperationID, "GetUserByUserID failed ", fErr.Error(), v)
3 years ago
resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: v, Result: -1})
3 years ago
} else {
3 years ago
if _, err := imdb.GetFriendRelationshipFromFriend(req.FromUserID, v); err != nil {
3 years ago
//Establish two single friendship
3 years ago
toInsertFollow := db.Friend{OwnerUserID: req.FromUserID, FriendUserID: v}
3 years ago
err1 := imdb.InsertToFriend(&toInsertFollow)
3 years ago
if err1 != nil {
3 years ago
log.NewError(req.OperationID, "InsertToFriend failed ", err1.Error(), toInsertFollow)
3 years ago
resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: v, Result: -1})
3 years ago
continue
}
3 years ago
toInsertFollow = db.Friend{OwnerUserID: v, FriendUserID: req.FromUserID}
3 years ago
err2 := imdb.InsertToFriend(&toInsertFollow)
3 years ago
if err2 != nil {
3 years ago
log.NewError(req.OperationID, "InsertToFriend failed ", err2.Error(), toInsertFollow)
3 years ago
resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: v, Result: -1})
3 years ago
continue
}
3 years ago
resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: v, Result: 0})
3 years ago
log.NewDebug(req.OperationID, "UserIDResultList ", resp.UserIDResultList)
3 years ago
chat.FriendAddedNotification(req.OperationID, req.OpUserID, req.FromUserID, v)
3 years ago
} else {
log.NewWarn(req.OperationID, "GetFriendRelationshipFromFriend ok", req.FromUserID, v)
resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: v, Result: 0})
3 years ago
}
}
}
2 years ago
2 years ago
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
2 years ago
if etcdConn == nil {
2 years ago
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
2 years ago
log.NewError(req.OperationID, errMsg)
resp.CommonResp.ErrMsg = errMsg
resp.CommonResp.ErrCode = 500
return &resp, nil
}
cacheClient := pbCache.NewCacheClient(etcdConn)
cacheResp, err := cacheClient.DelFriendIDListFromCache(context.Background(), &pbCache.DelFriendIDListFromCacheReq{UserID: req.FromUserID, OperationID: req.OperationID})
if err != nil {
log.NewError(req.OperationID, "DelBlackIDListFromCache rpc call failed ", err.Error())
resp.CommonResp.ErrCode = 500
resp.CommonResp.ErrMsg = err.Error()
return &resp, nil
}
if cacheResp.CommonResp.ErrCode != 0 {
log.NewError(req.OperationID, "DelBlackIDListFromCache rpc logic call failed ", cacheResp.String())
resp.CommonResp.ErrCode = 500
resp.CommonResp.ErrMsg = cacheResp.CommonResp.ErrMsg
return &resp, nil
}
if err := rocksCache.DelAllFriendsInfoFromCache(req.FromUserID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.FromUserID)
}
for _, userID := range req.FriendUserIDList {
cacheResp, err := cacheClient.DelFriendIDListFromCache(context.Background(), &pbCache.DelFriendIDListFromCacheReq{UserID: userID, OperationID: req.OperationID})
if err != nil {
log.NewError(req.OperationID, "DelBlackIDListFromCache rpc call failed ", err.Error())
}
if cacheResp != nil && cacheResp.CommonResp != nil {
if cacheResp.CommonResp.ErrCode != 0 {
log.NewError(req.OperationID, "DelBlackIDListFromCache rpc logic call failed ", cacheResp.String())
resp.CommonResp.ErrCode = 500
resp.CommonResp.ErrMsg = cacheResp.CommonResp.ErrMsg
return &resp, nil
}
}
if err := rocksCache.DelAllFriendsInfoFromCache(userID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), userID)
}
}
2 years ago
3 years ago
resp.CommonResp.ErrCode = 0
log.NewInfo(req.OperationID, "ImportFriend rpc ok ", resp.String())
3 years ago
return &resp, nil
}
3 years ago
//process Friend application
3 years ago
func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddFriendResponseReq) (*pbFriend.AddFriendResponseResp, error) {
3 years ago
log.NewInfo(req.CommID.OperationID, "AddFriendResponse args ", req.String())
3 years ago
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
3 years ago
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
3 years ago
}
//Check there application before agreeing or refuse to a friend's application
//req.CommID.FromUserID process req.CommID.ToUserID
3 years ago
friendRequest, err := imdb.GetFriendApplicationByBothUserID(req.CommID.ToUserID, req.CommID.FromUserID)
if err != nil {
log.NewError(req.CommID.OperationID, "GetFriendApplicationByBothUserID failed ", err.Error(), req.CommID.ToUserID, req.CommID.FromUserID)
3 years ago
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
3 years ago
}
3 years ago
friendRequest.HandleResult = req.HandleResult
3 years ago
friendRequest.HandleTime = time.Now()
3 years ago
//friendRequest.HandleTime.Unix()
3 years ago
friendRequest.HandleMsg = req.HandleMsg
friendRequest.HandlerUserID = req.CommID.OpUserID
3 years ago
err = imdb.UpdateFriendApplication(friendRequest)
3 years ago
if err != nil {
3 years ago
log.NewError(req.CommID.OperationID, "UpdateFriendApplication failed ", err.Error(), friendRequest)
3 years ago
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
3 years ago
}
3 years ago
3 years ago
//Change the status of the friend request form
3 years ago
if req.HandleResult == constant.FriendFlag {
2 years ago
var isInsert int
3 years ago
//Establish friendship after find friend relationship not exists
3 years ago
_, err := imdb.GetFriendRelationshipFromFriend(req.CommID.FromUserID, req.CommID.ToUserID)
3 years ago
if err == nil {
3 years ago
log.NewWarn(req.CommID.OperationID, "GetFriendRelationshipFromFriend exist", req.CommID.FromUserID, req.CommID.ToUserID)
3 years ago
} else {
//Establish two single friendship
3 years ago
toInsertFollow := db.Friend{OwnerUserID: req.CommID.FromUserID, FriendUserID: req.CommID.ToUserID, OperatorUserID: req.CommID.OpUserID}
3 years ago
err = imdb.InsertToFriend(&toInsertFollow)
3 years ago
if err != nil {
3 years ago
log.NewError(req.CommID.OperationID, "InsertToFriend failed ", err.Error(), toInsertFollow)
3 years ago
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
3 years ago
}
2 years ago
isInsert = 1
3 years ago
}
3 years ago
_, err = imdb.GetFriendRelationshipFromFriend(req.CommID.ToUserID, req.CommID.FromUserID)
3 years ago
if err == nil {
3 years ago
log.NewWarn(req.CommID.OperationID, "GetFriendRelationshipFromFriend exist", req.CommID.ToUserID, req.CommID.FromUserID)
3 years ago
} else {
3 years ago
toInsertFollow := db.Friend{OwnerUserID: req.CommID.ToUserID, FriendUserID: req.CommID.FromUserID, OperatorUserID: req.CommID.OpUserID}
3 years ago
err = imdb.InsertToFriend(&toInsertFollow)
if err != nil {
log.NewError(req.CommID.OperationID, "InsertToFriend failed ", err.Error(), toInsertFollow)
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
2 years ago
isInsert = 1
}
// cache rpc
if isInsert == 1 {
2 years ago
delFriendIDListFromCacheReq := &pbCache.DelFriendIDListFromCacheReq{OperationID: req.CommID.OperationID}
2 years ago
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.CommID.OperationID)
if etcdConn == nil {
2 years ago
errMsg := req.CommID.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.CommID.OperationID, errMsg)
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil
}
client := pbCache.NewCacheClient(etcdConn)
2 years ago
delFriendIDListFromCacheReq.UserID = req.CommID.ToUserID
respPb, err := client.DelFriendIDListFromCache(context.Background(), delFriendIDListFromCacheReq)
if err != nil {
2 years ago
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "DelFriendIDListFromCache failed", err.Error())
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrServer.ErrCode, ErrMsg: constant.ErrServer.ErrMsg}}, nil
}
if respPb.CommonResp.ErrCode != 0 {
2 years ago
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "DelFriendIDListFromCache failed", respPb.CommonResp.String())
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: respPb.CommonResp.ErrCode, ErrMsg: respPb.CommonResp.ErrMsg}}, nil
}
2 years ago
delFriendIDListFromCacheReq.UserID = req.CommID.FromUserID
respPb, err = client.DelFriendIDListFromCache(context.Background(), delFriendIDListFromCacheReq)
if err != nil {
2 years ago
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "DelFriendIDListFromCache failed", err.Error())
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrServer.ErrCode, ErrMsg: constant.ErrServer.ErrMsg}}, nil
}
if respPb.CommonResp.ErrCode != 0 {
2 years ago
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "DelFriendIDListFromCache failed", respPb.CommonResp.String())
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: respPb.CommonResp.ErrCode, ErrMsg: respPb.CommonResp.ErrMsg}}, nil
}
if err := rocksCache.DelAllFriendsInfoFromCache(req.CommID.ToUserID); err != nil {
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), err.Error(), req.CommID.ToUserID)
}
if err := rocksCache.DelAllFriendsInfoFromCache(req.CommID.FromUserID); err != nil {
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), err.Error(), req.CommID.FromUserID)
}
3 years ago
chat.FriendAddedNotification(req.CommID.OperationID, req.CommID.OpUserID, req.CommID.FromUserID, req.CommID.ToUserID)
3 years ago
}
}
3 years ago
if req.HandleResult == constant.FriendResponseAgree {
chat.FriendApplicationApprovedNotification(req)
} else if req.HandleResult == constant.FriendResponseRefuse {
chat.FriendApplicationRejectedNotification(req)
} else {
log.Error(req.CommID.OperationID, "HandleResult failed ", req.HandleResult)
}
3 years ago
3 years ago
log.NewInfo(req.CommID.OperationID, "rpc AddFriendResponse ok")
3 years ago
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{}}, nil
3 years ago
}
3 years ago
func (s *friendServer) DeleteFriend(ctx context.Context, req *pbFriend.DeleteFriendReq) (*pbFriend.DeleteFriendResp, error) {
3 years ago
log.NewInfo(req.CommID.OperationID, "DeleteFriend args ", req.String())
//Parse token, to find current user information
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
3 years ago
return &pbFriend.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
3 years ago
}
err := imdb.DeleteSingleFriendInfo(req.CommID.FromUserID, req.CommID.ToUserID)
if err != nil {
log.NewError(req.CommID.OperationID, "DeleteSingleFriendInfo failed", err.Error(), req.CommID.FromUserID, req.CommID.ToUserID)
3 years ago
return &pbFriend.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
3 years ago
}
log.NewInfo(req.CommID.OperationID, "DeleteFriend rpc ok")
2 years ago
2 years ago
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.CommID.OperationID)
if etcdConn == nil {
2 years ago
errMsg := req.CommID.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.CommID.OperationID, errMsg)
return &pbFriend.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil
}
3 years ago
client := pbCache.NewCacheClient(etcdConn)
2 years ago
respPb, err := client.DelFriendIDListFromCache(context.Background(), &pbCache.DelFriendIDListFromCacheReq{OperationID: req.CommID.OperationID, UserID: req.CommID.FromUserID})
3 years ago
if err != nil {
2 years ago
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "DelFriendIDListFromCache rpc failed", err.Error())
3 years ago
return &pbFriend.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrServer.ErrCode, ErrMsg: constant.ErrServer.ErrMsg}}, nil
}
if respPb.CommonResp.ErrCode != 0 {
2 years ago
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "DelFriendIDListFromCache failed", respPb.CommonResp.String())
3 years ago
return &pbFriend.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: respPb.CommonResp.ErrCode, ErrMsg: respPb.CommonResp.ErrMsg}}, nil
}
if err := rocksCache.DelAllFriendsInfoFromCache(req.CommID.FromUserID); err != nil {
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), err.Error(), req.CommID.FromUserID)
}
if err := rocksCache.DelAllFriendsInfoFromCache(req.CommID.ToUserID); err != nil {
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), err.Error(), req.CommID.FromUserID)
}
chat.FriendDeletedNotification(req)
3 years ago
return &pbFriend.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{}}, nil
3 years ago
}
func (s *friendServer) GetBlacklist(ctx context.Context, req *pbFriend.GetBlacklistReq) (*pbFriend.GetBlacklistResp, error) {
log.NewInfo(req.CommID.OperationID, "GetBlacklist args ", req.String())
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
3 years ago
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
3 years ago
return &pbFriend.GetBlacklistResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
3 years ago
}
2 years ago
blackIDList, err := rocksCache.GetBlackListFromCache(req.CommID.FromUserID)
3 years ago
if err != nil {
log.NewError(req.CommID.OperationID, "GetBlackListByUID failed ", err.Error(), req.CommID.FromUserID)
3 years ago
return &pbFriend.GetBlacklistResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
3 years ago
}
var (
3 years ago
userInfoList []*sdkws.PublicUserInfo
3 years ago
)
2 years ago
for _, userID := range blackIDList {
user, err := rocksCache.GetUserInfoFromCache(userID)
3 years ago
if err != nil {
2 years ago
log.NewError(req.CommID.OperationID, "GetUserByUserID failed ", err.Error(), userID)
3 years ago
continue
}
2 years ago
var blackUserInfo sdkws.PublicUserInfo
utils.CopyStructFields(&blackUserInfo, user)
3 years ago
userInfoList = append(userInfoList, &blackUserInfo)
}
3 years ago
log.NewInfo(req.CommID.OperationID, "rpc GetBlacklist ok ", pbFriend.GetBlacklistResp{BlackUserInfoList: userInfoList})
3 years ago
return &pbFriend.GetBlacklistResp{BlackUserInfoList: userInfoList}, nil
3 years ago
}
3 years ago
func (s *friendServer) SetFriendRemark(ctx context.Context, req *pbFriend.SetFriendRemarkReq) (*pbFriend.SetFriendRemarkResp, error) {
3 years ago
log.NewInfo(req.CommID.OperationID, "SetFriendComment args ", req.String())
//Parse token, to find current user information
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
3 years ago
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
3 years ago
return &pbFriend.SetFriendRemarkResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
3 years ago
}
3 years ago
err := imdb.UpdateFriendComment(req.CommID.FromUserID, req.CommID.ToUserID, req.Remark)
3 years ago
if err != nil {
2 years ago
log.NewError(req.CommID.OperationID, "UpdateFriendComment failed ", req.CommID.FromUserID, req.CommID.ToUserID, req.Remark, err.Error())
3 years ago
return &pbFriend.SetFriendRemarkResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
3 years ago
}
log.NewInfo(req.CommID.OperationID, "rpc SetFriendComment ok")
2 years ago
err = rocksCache.DelAllFriendsInfoFromCache(req.CommID.FromUserID)
if err != nil {
log.NewError(req.CommID.OperationID, "DelAllFriendInfoFromCache failed ", req.CommID.FromUserID, err.Error())
return &pbFriend.SetFriendRemarkResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
3 years ago
chat.FriendRemarkSetNotification(req.CommID.OperationID, req.CommID.OpUserID, req.CommID.FromUserID, req.CommID.ToUserID)
3 years ago
return &pbFriend.SetFriendRemarkResp{CommonResp: &pbFriend.CommonResp{}}, nil
3 years ago
}
3 years ago
func (s *friendServer) RemoveBlacklist(ctx context.Context, req *pbFriend.RemoveBlacklistReq) (*pbFriend.RemoveBlacklistResp, error) {
3 years ago
log.NewInfo(req.CommID.OperationID, "RemoveBlacklist args ", req.String())
//Parse token, to find current user information
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
3 years ago
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
3 years ago
return &pbFriend.RemoveBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
3 years ago
}
err := imdb.RemoveBlackList(req.CommID.FromUserID, req.CommID.ToUserID)
if err != nil {
log.NewError(req.CommID.OperationID, "RemoveBlackList failed", err.Error(), req.CommID.FromUserID, req.CommID.ToUserID)
3 years ago
return &pbFriend.RemoveBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
3 years ago
}
3 years ago
log.NewInfo(req.CommID.OperationID, "rpc RemoveBlacklist ok ")
2 years ago
2 years ago
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.CommID.OperationID)
if etcdConn == nil {
2 years ago
errMsg := req.CommID.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.CommID.OperationID, errMsg)
return &pbFriend.RemoveBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil
}
cacheClient := pbCache.NewCacheClient(etcdConn)
2 years ago
cacheResp, err := cacheClient.DelBlackIDListFromCache(context.Background(), &pbCache.DelBlackIDListFromCacheReq{UserID: req.CommID.FromUserID, OperationID: req.CommID.OperationID})
if err != nil {
2 years ago
log.NewError(req.CommID.OperationID, "DelBlackIDListFromCache rpc call failed ", err.Error())
return &pbFriend.RemoveBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: 500, ErrMsg: "ReduceBlackUserFromCache rpc call failed"}}, nil
}
if cacheResp.CommonResp.ErrCode != 0 {
2 years ago
log.NewError(req.CommID.OperationID, "DelBlackIDListFromCache rpc logic call failed ", cacheResp.CommonResp.String())
return &pbFriend.RemoveBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}}, nil
}
3 years ago
chat.BlackDeletedNotification(req)
3 years ago
return &pbFriend.RemoveBlacklistResp{CommonResp: &pbFriend.CommonResp{}}, nil
3 years ago
}
func (s *friendServer) IsInBlackList(ctx context.Context, req *pbFriend.IsInBlackListReq) (*pbFriend.IsInBlackListResp, error) {
log.NewInfo("IsInBlackList args ", req.String())
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
3 years ago
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
3 years ago
return &pbFriend.IsInBlackListResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
3 years ago
}
2 years ago
blackIDList, err := rocksCache.GetBlackListFromCache(req.CommID.FromUserID)
if err != nil {
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), err.Error(), req.CommID.FromUserID)
return &pbFriend.IsInBlackListResp{ErrMsg: err.Error(), ErrCode: constant.ErrDB.ErrCode}, nil
}
var isInBlacklist bool
if utils.IsContain(req.CommID.ToUserID, blackIDList) {
3 years ago
isInBlacklist = true
}
3 years ago
log.NewInfo(req.CommID.OperationID, "IsInBlackList rpc ok ", pbFriend.IsInBlackListResp{Response: isInBlacklist})
3 years ago
return &pbFriend.IsInBlackListResp{Response: isInBlacklist}, nil
}
func (s *friendServer) IsFriend(ctx context.Context, req *pbFriend.IsFriendReq) (*pbFriend.IsFriendResp, error) {
3 years ago
log.NewInfo(req.CommID.OperationID, req.String())
3 years ago
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
3 years ago
return &pbFriend.IsFriendResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
3 years ago
}
2 years ago
friendIDList, err := rocksCache.GetFriendIDListFromCache(req.CommID.FromUserID)
if err != nil {
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), err.Error(), req.CommID.FromUserID)
return &pbFriend.IsFriendResp{ErrMsg: err.Error(), ErrCode: constant.ErrDB.ErrCode}, nil
}
var isFriend bool
if utils.IsContain(req.CommID.ToUserID, friendIDList) {
3 years ago
isFriend = true
3 years ago
}
3 years ago
log.NewInfo(req.CommID.OperationID, pbFriend.IsFriendResp{Response: isFriend})
3 years ago
return &pbFriend.IsFriendResp{Response: isFriend}, nil
3 years ago
}
func (s *friendServer) GetFriendList(ctx context.Context, req *pbFriend.GetFriendListReq) (*pbFriend.GetFriendListResp, error) {
log.NewInfo("GetFriendList args ", req.String())
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
3 years ago
return &pbFriend.GetFriendListResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
3 years ago
}
2 years ago
friendList, err := rocksCache.GetAllFriendsInfoFromCache(req.CommID.FromUserID)
3 years ago
if err != nil {
2 years ago
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "GetFriendIDListFromCache failed", err.Error(), req.CommID.FromUserID)
3 years ago
return &pbFriend.GetFriendListResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
3 years ago
}
2 years ago
3 years ago
var userInfoList []*sdkws.FriendInfo
2 years ago
for _, friendUser := range friendList {
3 years ago
friendUserInfo := sdkws.FriendInfo{FriendUser: &sdkws.UserInfo{}}
2 years ago
cp.FriendDBCopyOpenIM(&friendUserInfo, friendUser)
3 years ago
log.NewDebug(req.CommID.OperationID, "friends : ", friendUser, "openim friends: ", friendUserInfo)
3 years ago
userInfoList = append(userInfoList, &friendUserInfo)
}
3 years ago
log.NewInfo(req.CommID.OperationID, "rpc GetFriendList ok", pbFriend.GetFriendListResp{FriendInfoList: userInfoList})
return &pbFriend.GetFriendListResp{FriendInfoList: userInfoList}, nil
3 years ago
}
3 years ago
//received
3 years ago
func (s *friendServer) GetFriendApplyList(ctx context.Context, req *pbFriend.GetFriendApplyListReq) (*pbFriend.GetFriendApplyListResp, error) {
3 years ago
log.NewInfo(req.CommID.OperationID, "GetFriendApplyList args ", req.String())
//Parse token, to find current user information
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
3 years ago
return &pbFriend.GetFriendApplyListResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
3 years ago
}
// Find the current user friend applications received
3 years ago
ApplyUsersInfo, err := imdb.GetReceivedFriendsApplicationListByUserID(req.CommID.FromUserID)
3 years ago
if err != nil {
3 years ago
log.NewError(req.CommID.OperationID, "GetReceivedFriendsApplicationListByUserID ", err.Error(), req.CommID.FromUserID)
3 years ago
return &pbFriend.GetFriendApplyListResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
3 years ago
}
3 years ago
var appleUserList []*sdkws.FriendRequest
3 years ago
for _, applyUserInfo := range ApplyUsersInfo {
3 years ago
var userInfo sdkws.FriendRequest
3 years ago
cp.FriendRequestDBCopyOpenIM(&userInfo, &applyUserInfo)
// utils.CopyStructFields(&userInfo, applyUserInfo)
// u, err := imdb.GetUserByUserID(userInfo.FromUserID)
// if err != nil {
// log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.FromUserID)
// continue
// }
// userInfo.FromNickname = u.Nickname
// userInfo.FromFaceURL = u.FaceURL
// userInfo.FromGender = u.Gender
//
// u, err = imdb.GetUserByUserID(userInfo.ToUserID)
// if err != nil {
// log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.ToUserID)
// continue
// }
// userInfo.ToNickname = u.Nickname
// userInfo.ToFaceURL = u.FaceURL
// userInfo.ToGender = u.Gender
3 years ago
appleUserList = append(appleUserList, &userInfo)
}
3 years ago
3 years ago
log.NewInfo(req.CommID.OperationID, "rpc GetFriendApplyList ok", pbFriend.GetFriendApplyListResp{FriendRequestList: appleUserList})
return &pbFriend.GetFriendApplyListResp{FriendRequestList: appleUserList}, nil
3 years ago
}
3 years ago
func (s *friendServer) GetSelfApplyList(ctx context.Context, req *pbFriend.GetSelfApplyListReq) (*pbFriend.GetSelfApplyListResp, error) {
3 years ago
log.NewInfo(req.CommID.OperationID, "GetSelfApplyList args ", req.String())
3 years ago
3 years ago
//Parse token, to find current user information
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
3 years ago
return &pbFriend.GetSelfApplyListResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
3 years ago
}
// Find the self add other userinfo
3 years ago
usersInfo, err := imdb.GetSendFriendApplicationListByUserID(req.CommID.FromUserID)
3 years ago
if err != nil {
3 years ago
log.NewError(req.CommID.OperationID, "GetSendFriendApplicationListByUserID failed ", err.Error(), req.CommID.FromUserID)
3 years ago
return &pbFriend.GetSelfApplyListResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
3 years ago
}
3 years ago
var selfApplyOtherUserList []*sdkws.FriendRequest
3 years ago
for _, selfApplyOtherUserInfo := range usersInfo {
3 years ago
var userInfo sdkws.FriendRequest // pbFriend.ApplyUserInfo
3 years ago
cp.FriendRequestDBCopyOpenIM(&userInfo, &selfApplyOtherUserInfo)
3 years ago
//u, err := imdb.GetUserByUserID(userInfo.FromUserID)
//if err != nil {
// log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.FromUserID)
// continue
//}
//userInfo.FromNickname = u.Nickname
//userInfo.FromFaceURL = u.FaceURL
//userInfo.FromGender = u.Gender
//
//u, err = imdb.GetUserByUserID(userInfo.ToUserID)
//if err != nil {
// log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.ToUserID)
// continue
//}
//userInfo.ToNickname = u.Nickname
//userInfo.ToFaceURL = u.FaceURL
//userInfo.ToGender = u.Gender
3 years ago
3 years ago
selfApplyOtherUserList = append(selfApplyOtherUserList, &userInfo)
}
3 years ago
log.NewInfo(req.CommID.OperationID, "rpc GetSelfApplyList ok", pbFriend.GetSelfApplyListResp{FriendRequestList: selfApplyOtherUserList})
return &pbFriend.GetSelfApplyListResp{FriendRequestList: selfApplyOtherUserList}, nil
3 years ago
}
3 years ago
////
//func (s *friendServer) GetFriendsInfo(ctx context.Context, req *pbFriend.GetFriendsInfoReq) (*pbFriend.GetFriendInfoResp, error) {
// return nil, nil
//// log.NewInfo(req.CommID.OperationID, "GetFriendsInfo args ", req.String())
//// var (
//// isInBlackList int32
//// // isFriend int32
//// comment string
//// )
////
//// friendShip, err := imdb.FindFriendRelationshipFromFriend(req.CommID.FromUserID, req.CommID.ToUserID)
//// if err != nil {
//// log.NewError(req.CommID.OperationID, "FindFriendRelationshipFromFriend failed ", err.Error())
//// return &pbFriend.GetFriendInfoResp{ErrCode: constant.ErrSearchUserInfo.ErrCode, ErrMsg: constant.ErrSearchUserInfo.ErrMsg}, nil
//// // isFriend = constant.FriendFlag
//// }
//// comment = friendShip.Remark
////
//// friendUserInfo, err := imdb.FindUserByUID(req.CommID.ToUserID)
//// if err != nil {
//// log.NewError(req.CommID.OperationID, "FindUserByUID failed ", err.Error())
//// return &pbFriend.GetFriendInfoResp{ErrCode: constant.ErrSearchUserInfo.ErrCode, ErrMsg: constant.ErrSearchUserInfo.ErrMsg}, nil
//// }
////
//// err = imdb.FindRelationshipFromBlackList(req.CommID.FromUserID, req.CommID.ToUserID)
//// if err == nil {
//// isInBlackList = constant.BlackListFlag
//// }
////
//// resp := pbFriend.GetFriendInfoResp{ErrCode: 0, ErrMsg: "",}
////
//// utils.CopyStructFields(resp.FriendInfoList, friendUserInfo)
//// resp.Data.IsBlack = isInBlackList
//// resp.Data.OwnerUserID = req.CommID.FromUserID
//// resp.Data.Remark = comment
//// resp.Data.CreateTime = friendUserInfo.CreateTime
////
//// log.NewInfo(req.CommID.OperationID, "GetFriendsInfo ok ", resp)
//// return &resp, nil
////
//}