mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-23 09:50:27 +08:00
friend rpc server update
This commit is contained in:
parent
540484f83f
commit
9f001ee2e6
@ -16,13 +16,12 @@ func (s *friendServer) AddBlacklist(ctx context.Context, req *pbFriend.AddBlackl
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||||
return &pbFriend.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
return &pbFriend.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||||
} else {
|
}
|
||||||
err := im_mysql_model.InsertInToUserBlackList(claims.UID, req.Uid)
|
err = im_mysql_model.InsertInToUserBlackList(claims.UID, req.Uid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(req.Token, req.OperationID, "err=%s,Failed to add blacklist", err.Error())
|
log.Error(req.Token, req.OperationID, "err=%s,Failed to add blacklist", err.Error())
|
||||||
return &pbFriend.CommonResp{ErrorCode: config.ErrMysql.ErrCode, ErrorMsg: config.ErrMysql.ErrMsg}, nil
|
return &pbFriend.CommonResp{ErrorCode: config.ErrMysql.ErrCode, ErrorMsg: config.ErrMysql.ErrMsg}, nil
|
||||||
}
|
}
|
||||||
}
|
|
||||||
log.Info(req.Token, req.OperationID, "rpc add blacklist success return,uid=%s", req.Uid)
|
log.Info(req.Token, req.OperationID, "rpc add blacklist success return,uid=%s", req.Uid)
|
||||||
return &pbFriend.CommonResp{}, nil
|
return &pbFriend.CommonResp{}, nil
|
||||||
}
|
}
|
||||||
|
@ -21,10 +21,16 @@ func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq
|
|||||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||||
return &pbFriend.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
return &pbFriend.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||||
}
|
}
|
||||||
|
//Cannot add non-existent users
|
||||||
|
if _, err = im_mysql_model.FindUserByUID(req.Uid); err != nil {
|
||||||
|
log.Error(req.Token, req.OperationID, "this user not exists,cant not add friend")
|
||||||
|
return &pbFriend.CommonResp{ErrorCode: config.ErrAddFriend.ErrCode, ErrorMsg: config.ErrSearchUserInfo.ErrMsg}, nil
|
||||||
|
}
|
||||||
|
|
||||||
//Establish a latest relationship in the friend request table
|
//Establish a latest relationship in the friend request table
|
||||||
err = im_mysql_model.ReplaceIntoFriendReq(claims.UID, req.Uid, constant.NotFriendFlag, req.ReqMessage)
|
err = im_mysql_model.ReplaceIntoFriendReq(claims.UID, req.Uid, constant.ApplicationFriendFlag, req.ReqMessage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(req.Token, req.OperationID, "err=%s,create friend request ship failed", err.Error())
|
log.Error(req.Token, req.OperationID, "err=%s,create friend request record failed", err.Error())
|
||||||
return &pbFriend.CommonResp{ErrorCode: config.ErrAddFriend.ErrCode, ErrorMsg: config.ErrAddFriend.ErrMsg}, nil
|
return &pbFriend.CommonResp{ErrorCode: config.ErrAddFriend.ErrCode, ErrorMsg: config.ErrAddFriend.ErrMsg}, nil
|
||||||
}
|
}
|
||||||
log.Info(req.Token, req.OperationID, "rpc add friend is success return,uid=%s", req.Uid)
|
log.Info(req.Token, req.OperationID, "rpc add friend is success return,uid=%s", req.Uid)
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *friendServer) AddedFriend(ctx context.Context, req *pbFriend.AddedFriendReq) (*pbFriend.CommonResp, error) {
|
func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddFriendResponseReq) (*pbFriend.CommonResp, error) {
|
||||||
log.Info(req.Token, req.OperationID, "rpc add friend response is server,args=%s", req.String())
|
log.Info(req.Token, req.OperationID, "rpc add friend response is server,args=%s", req.String())
|
||||||
//Parse token, to find current user information
|
//Parse token, to find current user information
|
||||||
claims, err := utils.ParseToken(req.Token)
|
claims, err := utils.ParseToken(req.Token)
|
||||||
@ -21,29 +21,34 @@ func (s *friendServer) AddedFriend(ctx context.Context, req *pbFriend.AddedFrien
|
|||||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||||
return &pbFriend.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
return &pbFriend.CommonResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||||
}
|
}
|
||||||
|
//Check there application before agreeing or refuse to a friend's application
|
||||||
|
if _, err = im_mysql_model.FindFriendApplyFromFriendReqByUid(req.Uid, claims.UID); err != nil {
|
||||||
|
log.Error(req.Token, req.OperationID, "No such application record")
|
||||||
|
return &pbFriend.CommonResp{ErrorCode: config.ErrAgreeToAddFriend.ErrCode, ErrorMsg: config.ErrAgreeToAddFriend.ErrMsg}, nil
|
||||||
|
}
|
||||||
|
//Change friend request status flag
|
||||||
err = im_mysql_model.UpdateFriendRelationshipToFriendReq(req.Uid, claims.UID, req.Flag)
|
err = im_mysql_model.UpdateFriendRelationshipToFriendReq(req.Uid, claims.UID, req.Flag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(req.Token, req.OperationID, "err=%s,update friend request table failed", err.Error())
|
log.Error(req.Token, req.OperationID, "err=%s,update friend request table failed", err.Error())
|
||||||
return &pbFriend.CommonResp{ErrorCode: config.ErrMysql.ErrCode, ErrorMsg: config.ErrMysql.ErrMsg}, nil
|
return &pbFriend.CommonResp{ErrorCode: config.ErrMysql.ErrCode, ErrorMsg: config.ErrAgreeToAddFriend.ErrMsg}, nil
|
||||||
}
|
}
|
||||||
log.Info(req.Token, req.OperationID, "rpc add friend response success return,userid=%s,flag=%d", req.Uid, req.Flag)
|
log.Info(req.Token, req.OperationID, "rpc add friend response success return,userid=%s,flag=%d", req.Uid, req.Flag)
|
||||||
//Change the status of the friend request form
|
//Change the status of the friend request form
|
||||||
if req.Flag == constant.FriendFlag {
|
if req.Flag == constant.FriendFlag {
|
||||||
//Establish friendship after find friend relationship not exists
|
//Establish friendship after find friend relationship not exists
|
||||||
_, err := im_mysql_model.FindFriendRelationshipFromFriend(claims.UID, req.Uid)
|
_, err := im_mysql_model.FindFriendRelationshipFromFriend(claims.UID, req.Uid)
|
||||||
if err == nil {
|
//fixme If there is an error, it means that there is no friend record or database err, if no friend record should be inserted,Continue down execution
|
||||||
return &pbFriend.CommonResp{ErrorCode: 0, ErrorMsg: "You are already friends"}, nil
|
if err != nil {
|
||||||
|
log.Error("", req.OperationID, err.Error())
|
||||||
}
|
}
|
||||||
//Establish two single friendship
|
//Establish two single friendship
|
||||||
err = im_mysql_model.InsertToFriend(claims.UID, req.Uid, req.Flag)
|
err = im_mysql_model.InsertToFriend(claims.UID, req.Uid, req.Flag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(req.Token, req.OperationID, "err=%s,create friendship failed", err.Error())
|
log.Error(req.Token, req.OperationID, "err=%s,create friendship failed", err.Error())
|
||||||
return &pbFriend.CommonResp{ErrorCode: config.ErrAddFriend.ErrCode, ErrorMsg: config.ErrAddFriend.ErrMsg}, nil
|
|
||||||
}
|
}
|
||||||
err = im_mysql_model.InsertToFriend(req.Uid, claims.UID, req.Flag)
|
err = im_mysql_model.InsertToFriend(req.Uid, claims.UID, req.Flag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(req.Token, req.OperationID, "err=%s,create friendship failed", err.Error())
|
log.Error(req.Token, req.OperationID, "err=%s,create friendship failed", err.Error())
|
||||||
return &pbFriend.CommonResp{ErrorCode: config.ErrAddFriend.ErrCode, ErrorMsg: config.ErrAddFriend.ErrMsg}, nil
|
|
||||||
}
|
}
|
||||||
//Push message when establish friends successfully
|
//Push message when establish friends successfully
|
||||||
senderInfo, errSend := im_mysql_model.FindUserByUID(claims.UID)
|
senderInfo, errSend := im_mysql_model.FindUserByUID(claims.UID)
|
||||||
@ -51,10 +56,25 @@ func (s *friendServer) AddedFriend(ctx context.Context, req *pbFriend.AddedFrien
|
|||||||
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||||
SendID: claims.UID,
|
SendID: claims.UID,
|
||||||
RecvID: req.Uid,
|
RecvID: req.Uid,
|
||||||
Content: content_struct.NewContentStructString(0, "", senderInfo.Name+" agreed to add you as a friend."),
|
Content: senderInfo.Name + " agreed to add you as a friend.",
|
||||||
SendTime: utils.GetCurrentTimestampBySecond(),
|
SendTime: utils.GetCurrentTimestampBySecond(),
|
||||||
MsgFrom: constant.SysMsgType, //Notification message identification
|
MsgFrom: constant.UserMsgType, //Notification message identification
|
||||||
ContentType: constant.AgreeAddFriendTip, //Add friend flag
|
ContentType: constant.AcceptFriendApplicationTip, //Add friend flag
|
||||||
|
SessionType: constant.SingleChatType,
|
||||||
|
OperationID: req.OperationID,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if req.Flag == constant.RefuseFriendFlag {
|
||||||
|
senderInfo, errSend := im_mysql_model.FindUserByUID(claims.UID)
|
||||||
|
if errSend == nil {
|
||||||
|
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||||
|
SendID: claims.UID,
|
||||||
|
RecvID: req.Uid,
|
||||||
|
Content: content_struct.NewContentStructString(0, "", senderInfo.Name+" refuse to add you as a friend."),
|
||||||
|
SendTime: utils.GetCurrentTimestampBySecond(),
|
||||||
|
MsgFrom: constant.UserMsgType, //Notification message identification
|
||||||
|
ContentType: constant.RefuseFriendApplicationTip, //Add friend flag
|
||||||
SessionType: constant.SingleChatType,
|
SessionType: constant.SingleChatType,
|
||||||
OperationID: req.OperationID,
|
OperationID: req.OperationID,
|
||||||
})
|
})
|
||||||
|
111
src/rpc/friend/friend/get_firends_info.go
Normal file
111
src/rpc/friend/friend/get_firends_info.go
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
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) GetFriendsInfo(ctx context.Context, req *pbFriend.GetFriendsInfoReq) (*pbFriend.GetFriendInfoResp, error) {
|
||||||
|
log.Info(req.Token, req.OperationID, "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.GetFriendInfoResp{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.GetFriendInfoResp{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.GetFriendInfoResp{
|
||||||
|
ErrorCode: 0,
|
||||||
|
ErrorMsg: "",
|
||||||
|
Data: &pbFriend.GetFriendData{
|
||||||
|
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
|
||||||
|
|
||||||
|
}
|
@ -29,19 +29,15 @@ func (s *friendServer) GetFriendApplyList(ctx context.Context, req *pbFriend.Get
|
|||||||
for _, applyUserInfo := range ApplyUsersInfo {
|
for _, applyUserInfo := range ApplyUsersInfo {
|
||||||
var userInfo pbFriend.ApplyUserInfo
|
var userInfo pbFriend.ApplyUserInfo
|
||||||
//Find friend application status
|
//Find friend application status
|
||||||
friendReqStatus, err := im_mysql_model.FindFriendRelationshipFromFriendReq(applyUserInfo.ReqId, applyUserInfo.UserId)
|
userInfo.Flag = applyUserInfo.Flag
|
||||||
if err != nil {
|
userInfo.ReqMessage = applyUserInfo.ReqMessage
|
||||||
log.Error(req.Token, req.OperationID, "err=%s,search friendRelationshipStatus failed", err.Error())
|
userInfo.ApplyTime = strconv.FormatInt(applyUserInfo.CreateTime.Unix(), 10)
|
||||||
} else {
|
|
||||||
userInfo.Flag = friendReqStatus.Flag
|
|
||||||
userInfo.ReqMessage = friendReqStatus.ReqMessage
|
|
||||||
userInfo.ApplyTime = strconv.FormatInt(friendReqStatus.CreateTime.Unix(), 10)
|
|
||||||
}
|
|
||||||
//Find user information
|
//Find user information
|
||||||
us, err := im_mysql_model.FindUserByUID(applyUserInfo.ReqId)
|
us, err := im_mysql_model.FindUserByUID(applyUserInfo.ReqId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(req.Token, req.OperationID, fmt.Sprintf("err=%s,search userInfo failed", err.Error()))
|
log.Error(req.Token, req.OperationID, "err=%s,search userInfo failed", err.Error())
|
||||||
} else {
|
continue
|
||||||
|
}
|
||||||
userInfo.Uid = us.UID
|
userInfo.Uid = us.UID
|
||||||
userInfo.Icon = us.Icon
|
userInfo.Icon = us.Icon
|
||||||
userInfo.Name = us.Name
|
userInfo.Name = us.Name
|
||||||
@ -51,8 +47,49 @@ func (s *friendServer) GetFriendApplyList(ctx context.Context, req *pbFriend.Get
|
|||||||
userInfo.Email = us.Email
|
userInfo.Email = us.Email
|
||||||
userInfo.Ex = us.Ex
|
userInfo.Ex = us.Ex
|
||||||
appleUserList = append(appleUserList, &userInfo)
|
appleUserList = append(appleUserList, &userInfo)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
log.Info(req.Token, req.OperationID, fmt.Sprintf("rpc get friendapplylist success return"))
|
log.Info(req.Token, req.OperationID, fmt.Sprintf("rpc get friendapplylist success return"))
|
||||||
return &pbFriend.GetFriendApplyResp{Data: appleUserList}, nil
|
return &pbFriend.GetFriendApplyResp{Data: appleUserList}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *friendServer) GetSelfApplyList(ctx context.Context, req *pbFriend.GetFriendApplyReq) (*pbFriend.GetFriendApplyResp, error) {
|
||||||
|
log.Info(req.Token, req.OperationID, "rpc get self apply list is server,args=%s", req.String())
|
||||||
|
var selfApplyOtherUserList []*pbFriend.ApplyUserInfo
|
||||||
|
//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.GetFriendApplyResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||||
|
}
|
||||||
|
// Find the self add other userinfo
|
||||||
|
usersInfo, err := im_mysql_model.FindSelfApplyFromFriendReq(claims.UID)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(req.Token, req.OperationID, "err=%s,search self to other user Info failed", err.Error())
|
||||||
|
return &pbFriend.GetFriendApplyResp{ErrorCode: config.ErrMysql.ErrCode, ErrorMsg: config.ErrMysql.ErrMsg}, nil
|
||||||
|
}
|
||||||
|
for _, selfApplyOtherUserInfo := range usersInfo {
|
||||||
|
var userInfo pbFriend.ApplyUserInfo
|
||||||
|
//Find friend application status
|
||||||
|
userInfo.Flag = selfApplyOtherUserInfo.Flag
|
||||||
|
userInfo.ReqMessage = selfApplyOtherUserInfo.ReqMessage
|
||||||
|
userInfo.ApplyTime = strconv.FormatInt(selfApplyOtherUserInfo.CreateTime.Unix(), 10)
|
||||||
|
//Find user information
|
||||||
|
us, err := im_mysql_model.FindUserByUID(selfApplyOtherUserInfo.Uid)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(req.Token, req.OperationID, "err=%s,search userInfo failed", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
userInfo.Uid = us.UID
|
||||||
|
userInfo.Icon = us.Icon
|
||||||
|
userInfo.Name = us.Name
|
||||||
|
userInfo.Gender = us.Gender
|
||||||
|
userInfo.Mobile = us.Mobile
|
||||||
|
userInfo.Birth = us.Birth
|
||||||
|
userInfo.Email = us.Email
|
||||||
|
userInfo.Ex = us.Ex
|
||||||
|
selfApplyOtherUserList = append(selfApplyOtherUserList, &userInfo)
|
||||||
|
}
|
||||||
|
log.Info(req.Token, req.OperationID, fmt.Sprintf("rpc get self apply list success return"))
|
||||||
|
return &pbFriend.GetFriendApplyResp{Data: selfApplyOtherUserList}, nil
|
||||||
|
}
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
pbFriend "Open_IM/src/proto/friend"
|
pbFriend "Open_IM/src/proto/friend"
|
||||||
"Open_IM/src/utils"
|
"Open_IM/src/utils"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *friendServer) GetFriendList(ctx context.Context, req *pbFriend.GetFriendListReq) (*pbFriend.GetFriendListResp, error) {
|
func (s *friendServer) GetFriendList(ctx context.Context, req *pbFriend.GetFriendListReq) (*pbFriend.GetFriendListResp, error) {
|
||||||
@ -39,7 +38,8 @@ func (s *friendServer) GetFriendList(ctx context.Context, req *pbFriend.GetFrien
|
|||||||
us, err := im_mysql_model.FindUserByUID(friendUser.FriendId)
|
us, err := im_mysql_model.FindUserByUID(friendUser.FriendId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(req.Token, req.OperationID, "err=%s search userInfo failed", err.Error())
|
log.Error(req.Token, req.OperationID, "err=%s search userInfo failed", err.Error())
|
||||||
} else {
|
continue
|
||||||
|
}
|
||||||
friendUserInfo.Uid = friendUser.FriendId
|
friendUserInfo.Uid = friendUser.FriendId
|
||||||
friendUserInfo.Comment = friendUser.Comment
|
friendUserInfo.Comment = friendUser.Comment
|
||||||
friendUserInfo.Icon = us.Icon
|
friendUserInfo.Icon = us.Icon
|
||||||
@ -51,9 +51,8 @@ func (s *friendServer) GetFriendList(ctx context.Context, req *pbFriend.GetFrien
|
|||||||
friendUserInfo.Ex = us.Ex
|
friendUserInfo.Ex = us.Ex
|
||||||
|
|
||||||
userInfoList = append(userInfoList, &friendUserInfo)
|
userInfoList = append(userInfoList, &friendUserInfo)
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
log.Info(req.Token, req.OperationID, fmt.Sprintf("rpc get friend list success return"))
|
log.Info(req.Token, req.OperationID, "rpc get friend list success return")
|
||||||
return &pbFriend.GetFriendListResp{Data: userInfoList}, nil
|
return &pbFriend.GetFriendListResp{Data: userInfoList}, nil
|
||||||
}
|
}
|
||||||
|
30
src/rpc/friend/friend/is_friend.go
Normal file
30
src/rpc/friend/friend/is_friend.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
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"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *friendServer) IsFriend(ctx context.Context, req *pbFriend.IsFriendReq) (*pbFriend.IsFriendResp, error) {
|
||||||
|
log.InfoByArgs("rpc is friend is server,args=%s", req.String())
|
||||||
|
var isFriend int32
|
||||||
|
claims, err := utils.ParseToken(req.Token)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||||
|
return &pbFriend.IsFriendResp{ErrorCode: config.ErrParseToken.ErrCode, ErrorMsg: config.ErrParseToken.ErrMsg}, nil
|
||||||
|
}
|
||||||
|
_, err = im_mysql_model.FindFriendRelationshipFromFriend(claims.UID, req.ReceiveUid)
|
||||||
|
if err == nil {
|
||||||
|
isFriend = constant.FriendFlag
|
||||||
|
} else {
|
||||||
|
isFriend = constant.ApplicationFriendFlag
|
||||||
|
}
|
||||||
|
log.InfoByArgs(fmt.Sprintf("rpc is friend success return"))
|
||||||
|
return &pbFriend.IsFriendResp{ShipType: isFriend}, nil
|
||||||
|
}
|
@ -12,9 +12,7 @@ func (s *friendServer) IsInBlackList(ctx context.Context, req *pbFriend.IsInBlac
|
|||||||
log.InfoByArgs("rpc is in blacklist is server,args=%s", req.String())
|
log.InfoByArgs("rpc is in blacklist is server,args=%s", req.String())
|
||||||
var isInBlacklist = false
|
var isInBlacklist = false
|
||||||
err := im_mysql_model.FindRelationshipFromBlackList(req.ReceiveUid, req.SendUid)
|
err := im_mysql_model.FindRelationshipFromBlackList(req.ReceiveUid, req.SendUid)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
log.Error("", req.OperationID, "err=%s,", err.Error())
|
|
||||||
} else {
|
|
||||||
isInBlacklist = true
|
isInBlacklist = true
|
||||||
}
|
}
|
||||||
log.InfoByArgs(fmt.Sprintf("rpc is in blackList success return"))
|
log.InfoByArgs(fmt.Sprintf("rpc is in blackList success return"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user