diff --git a/cmd/open_im_api/main.go b/cmd/open_im_api/main.go index ef297ca10..c43c317bf 100644 --- a/cmd/open_im_api/main.go +++ b/cmd/open_im_api/main.go @@ -42,6 +42,7 @@ func main() { userRouterGroup.POST("/get_users_info", user.GetUsersInfo) //1 userRouterGroup.POST("/get_self_user_info", user.GetSelfUserInfo) //1 userRouterGroup.POST("/get_users_online_status", user.GetUsersOnlineStatus) //1 + userRouterGroup.POST("/get_users_info_from_cache", user.GetUsersInfoFromCache) } //friend routing group friendRouterGroup := r.Group("/friend") diff --git a/internal/api/user/user.go b/internal/api/user/user.go index 4fbbcf5ef..93c800259 100644 --- a/internal/api/user/user.go +++ b/internal/api/user/user.go @@ -18,6 +18,45 @@ import ( "strings" ) +//todo +func GetUsersInfoFromCache(c *gin.Context) { + params := api.GetUsersInfoReq{} + if err := c.BindJSON(¶ms); err != nil { + log.NewError("0", "BindJSON failed ", err.Error()) + c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()}) + return + } + req := &rpc.GetUserInfoReq{} + utils.CopyStructFields(req, ¶ms) + var ok bool + ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID) + if !ok { + log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token")) + c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"}) + return + } + log.NewInfo(params.OperationID, "GetUserInfo args ", req.String()) + + etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) + client := rpc.NewUserClient(etcdConn) + RpcResp, err := client.GetUserInfo(context.Background(), req) + if err != nil { + log.NewError(req.OperationID, "GetUserInfo failed ", err.Error(), req.String()) + c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"}) + return + } + var publicUserInfoList []*open_im_sdk.PublicUserInfo + for _, v := range RpcResp.UserInfoList { + publicUserInfoList = append(publicUserInfoList, + &open_im_sdk.PublicUserInfo{UserID: v.UserID, Nickname: v.Nickname, FaceURL: v.FaceURL, Gender: v.Gender, Ex: v.Ex}) + } + + resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, UserInfoList: publicUserInfoList} + resp.Data = jsonData.JsonDataList(resp.UserInfoList) + log.NewInfo(req.OperationID, "GetUserInfo api return ", resp) + c.JSON(http.StatusOK, resp) +} + func GetUsersInfo(c *gin.Context) { params := api.GetUsersInfoReq{} if err := c.BindJSON(¶ms); err != nil { diff --git a/pkg/proto/friend/friend.proto b/pkg/proto/friend/friend.proto index 0050582d1..8f7827edc 100644 --- a/pkg/proto/friend/friend.proto +++ b/pkg/proto/friend/friend.proto @@ -166,4 +166,7 @@ service friend{ rpc addFriendResponse(AddFriendResponseReq) returns(AddFriendResponseResp); rpc setFriendRemark(SetFriendRemarkReq) returns(SetFriendRemarkResp); rpc importFriend(ImportFriendReq) returns(ImportFriendResp); + + rpc CheckFriendFromCache(IsFriendReq) returns(IsFriendResp); + rpc CheckBlockFromCache(IsInBlackListReq) returns(IsFriendResp); } \ No newline at end of file diff --git a/pkg/proto/user/user.proto b/pkg/proto/user/user.proto index d5914db41..3fbfd0162 100644 --- a/pkg/proto/user/user.proto +++ b/pkg/proto/user/user.proto @@ -315,4 +315,8 @@ service user { rpc GetBlockUsers(GetBlockUsersReq) returns (GetBlockUsersResp); rpc GetBlockUserById(GetBlockUserByIdReq) returns (GetBlockUserByIdResp); rpc DeleteUser(DeleteUserReq) returns (DeleteUserResp); + + + rpc GetUserInfoFromCache(GetUserInfoReq) returns(GetUserInfoResp); + }