mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-05-23 05:19:43 +08:00
del
This commit is contained in:
parent
2d41b0ff4f
commit
4c90036f2a
@ -1,71 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/log"
|
||||
pbFriend "Open_IM/src/proto/friend"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type paramsSearchFriend struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
UID string `json:"uid" binding:"required"`
|
||||
}
|
||||
|
||||
func SearchFriend(c *gin.Context) {
|
||||
log.Info("", "", fmt.Sprintf("api search friend init ...."))
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
defer etcdConn.Close()
|
||||
|
||||
params := paramsSearchFriend{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbFriend.SearchFriendReq{
|
||||
Uid: params.UID,
|
||||
OperationID: params.OperationID,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "api search_friend is server")
|
||||
RpcResp, err := client.SearchFriend(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,call search friend rpc server failed", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call search friend rpc server failed"})
|
||||
return
|
||||
}
|
||||
log.InfoByArgs("call search friend rpc server success,args=%s", RpcResp.String())
|
||||
if RpcResp.ErrorCode == 0 {
|
||||
resp := gin.H{
|
||||
"errCode": RpcResp.ErrorCode,
|
||||
"errMsg": RpcResp.ErrorMsg,
|
||||
"data": gin.H{
|
||||
"uid": RpcResp.Data.Uid,
|
||||
"icon": RpcResp.Data.Icon,
|
||||
"name": RpcResp.Data.Name,
|
||||
"gender": RpcResp.Data.Gender,
|
||||
"mobile": RpcResp.Data.Mobile,
|
||||
"birth": RpcResp.Data.Birth,
|
||||
"email": RpcResp.Data.Email,
|
||||
"ex": RpcResp.Data.Ex,
|
||||
"comment": RpcResp.Data.Comment,
|
||||
"isFriend": RpcResp.Data.IsFriend,
|
||||
"isInBlackList": RpcResp.Data.IsInBlackList,
|
||||
},
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
} else {
|
||||
resp := gin.H{
|
||||
"errCode": RpcResp.ErrorCode,
|
||||
"errMsg": RpcResp.ErrorMsg,
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
log.InfoByArgs("api search_friend success return,get args=%s,return=%s", req.String(), RpcResp.String())
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/constant"
|
||||
"Open_IM/src/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/src/common/log"
|
||||
pbFriend "Open_IM/src/proto/friend"
|
||||
"Open_IM/src/utils"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type friendServer struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
}
|
||||
|
||||
func NewFriendServer(port int) *friendServer {
|
||||
return &friendServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImFriendName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *friendServer) Run() {
|
||||
log.Info("", "", fmt.Sprintf("rpc friend init...."))
|
||||
|
||||
ip := utils.ServerIP
|
||||
registerAddress := ip + ":" + strconv.Itoa(s.rpcPort)
|
||||
//listener network
|
||||
listener, err := net.Listen("tcp", registerAddress)
|
||||
if err != nil {
|
||||
log.InfoByArgs(fmt.Sprintf("Failed to listen rpc friend network,err=%s", err.Error()))
|
||||
return
|
||||
}
|
||||
log.Info("", "", "listen network success, address = %s", registerAddress)
|
||||
defer listener.Close()
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
//User friend related services register to etcd
|
||||
pbFriend.RegisterFriendServer(srv, s)
|
||||
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), ip, s.rpcPort, s.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
log.ErrorByArgs("register rpc fiend service to etcd failed,err=%s", err.Error())
|
||||
return
|
||||
}
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.ErrorByArgs("listen rpc friend error,err=%s", err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (s *friendServer) SearchFriend(ctx context.Context, req *pbFriend.SearchFriendReq) (*pbFriend.SearchFriendResp, error) {
|
||||
log.Info(req.Token, req.OperationID, fmt.Sprintf("rpc search user is server,args=%s", req.String()))
|
||||
var (
|
||||
isInBlackList int32
|
||||
isFriend int32
|
||||
comment string
|
||||
)
|
||||
//Parse token, to find current user information
|
||||
claims, err := utils.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.SearchFriendResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
friendShip, err := im_mysql_model.FindFriendRelationshipFromFriend(claims.UID, req.Uid)
|
||||
if err == nil {
|
||||
isFriend = constant.FriendFlag
|
||||
comment = friendShip.Comment
|
||||
}
|
||||
friendUserInfo, err := im_mysql_model.FindUserByUID(req.Uid)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,no this user", err.Error())
|
||||
return &pbFriend.SearchFriendResp{ErrorCode: config.ErrSearchUserInfo.ErrCode, ErrorMsg: config.ErrSearchUserInfo.ErrMsg}, nil
|
||||
}
|
||||
err = im_mysql_model.FindRelationshipFromBlackList(claims.UID, req.Uid)
|
||||
if err == nil {
|
||||
isInBlackList = constant.BlackListFlag
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc search friend success return")
|
||||
return &pbFriend.SearchFriendResp{
|
||||
ErrorCode: 0,
|
||||
ErrorMsg: "",
|
||||
Data: &pbFriend.SearchFriendData{
|
||||
Uid: friendUserInfo.UID,
|
||||
Icon: friendUserInfo.Icon,
|
||||
Name: friendUserInfo.Name,
|
||||
Gender: friendUserInfo.Gender,
|
||||
Mobile: friendUserInfo.Mobile,
|
||||
Birth: friendUserInfo.Birth,
|
||||
Email: friendUserInfo.Email,
|
||||
Ex: friendUserInfo.Ex,
|
||||
Comment: comment,
|
||||
IsFriend: isFriend,
|
||||
IsInBlackList: isInBlackList,
|
||||
},
|
||||
}, nil
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user