|
|
@ -26,111 +26,207 @@ func GetUsersInfoFromCache(c *gin.Context) {
|
|
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()})
|
|
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()})
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
getUserInfoReq := &rpc.GetUserInfoReq{}
|
|
|
|
req := &rpc.GetUserInfoReq{}
|
|
|
|
getUserInfoReq.OperationID = params.OperationID
|
|
|
|
utils.CopyStructFields(req, ¶ms)
|
|
|
|
var ok bool
|
|
|
|
var ok bool
|
|
|
|
ok, getUserInfoReq.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), getUserInfoReq.OperationID)
|
|
|
|
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
|
|
|
if !ok {
|
|
|
|
if !ok {
|
|
|
|
log.NewError(getUserInfoReq.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
|
|
|
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.NewInfo(params.OperationID, "GetUserInfo args ", getUserInfoReq.String())
|
|
|
|
log.NewInfo(params.OperationID, "GetUserInfo args ", req.String())
|
|
|
|
reqCacheGetUserInfo := &cacheRpc.GetUserInfoFromCacheReq{}
|
|
|
|
|
|
|
|
utils.CopyStructFields(reqCacheGetUserInfo, ¶ms)
|
|
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
|
|
|
var userInfoList []*open_im_sdk.UserInfo
|
|
|
|
client := rpc.NewUserClient(etcdConn)
|
|
|
|
var publicUserInfoList []*open_im_sdk.PublicUserInfo
|
|
|
|
RpcResp, err := client.GetUserInfo(context.Background(), req)
|
|
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName)
|
|
|
|
|
|
|
|
cacheClient := cacheRpc.NewCacheClient(etcdConn)
|
|
|
|
|
|
|
|
cacheResp, err := cacheClient.GetUserInfoFromCache(context.Background(), reqCacheGetUserInfo)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.NewError(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed", err.Error())
|
|
|
|
log.NewError(req.OperationID, "GetUserInfo failed ", err.Error(), req.String())
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed: " + err.Error()})
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if cacheResp.CommonResp.ErrCode != 0 {
|
|
|
|
var publicUserInfoList []*open_im_sdk.PublicUserInfo
|
|
|
|
log.NewError(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed", cacheResp.CommonResp)
|
|
|
|
for _, v := range RpcResp.UserInfoList {
|
|
|
|
resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}}
|
|
|
|
publicUserInfoList = append(publicUserInfoList,
|
|
|
|
resp.Data = []map[string]interface{}{}
|
|
|
|
&open_im_sdk.PublicUserInfo{UserID: v.UserID, Nickname: v.Nickname, FaceURL: v.FaceURL, Gender: v.Gender, Ex: v.Ex})
|
|
|
|
log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp)
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, resp)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.NewInfo(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "cacheResp:", cacheResp.String())
|
|
|
|
|
|
|
|
userInfoList = cacheResp.UserInfoList
|
|
|
|
resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, UserInfoList: publicUserInfoList}
|
|
|
|
var needCacheUserIDList []string
|
|
|
|
resp.Data = jsonData.JsonDataList(resp.UserInfoList)
|
|
|
|
for _, userID := range reqCacheGetUserInfo.UserIDList {
|
|
|
|
log.NewInfo(req.OperationID, "GetUserInfo api return ", resp)
|
|
|
|
isGetUserInfoFromCache := false
|
|
|
|
c.JSON(http.StatusOK, resp)
|
|
|
|
for _, cacheUser := range userInfoList {
|
|
|
|
}
|
|
|
|
if cacheUser.UserID == userID {
|
|
|
|
|
|
|
|
isGetUserInfoFromCache = true
|
|
|
|
//func GetUsersInfoFromCache(c *gin.Context) {
|
|
|
|
}
|
|
|
|
// params := api.GetUsersInfoReq{}
|
|
|
|
}
|
|
|
|
// if err := c.BindJSON(¶ms); err != nil {
|
|
|
|
if !isGetUserInfoFromCache {
|
|
|
|
// log.NewError("0", "BindJSON failed ", err.Error())
|
|
|
|
needCacheUserIDList = append(needCacheUserIDList, userID)
|
|
|
|
// c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()})
|
|
|
|
}
|
|
|
|
// return
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// getUserInfoReq := &rpc.GetUserInfoReq{}
|
|
|
|
|
|
|
|
// getUserInfoReq.OperationID = params.OperationID
|
|
|
|
|
|
|
|
// var ok bool
|
|
|
|
|
|
|
|
// ok, getUserInfoReq.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), getUserInfoReq.OperationID)
|
|
|
|
|
|
|
|
// if !ok {
|
|
|
|
|
|
|
|
// log.NewError(getUserInfoReq.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 ", getUserInfoReq.String())
|
|
|
|
|
|
|
|
// reqCacheGetUserInfo := &cacheRpc.GetUserInfoFromCacheReq{}
|
|
|
|
|
|
|
|
// utils.CopyStructFields(reqCacheGetUserInfo, ¶ms)
|
|
|
|
|
|
|
|
// var userInfoList []*open_im_sdk.UserInfo
|
|
|
|
|
|
|
|
// var publicUserInfoList []*open_im_sdk.PublicUserInfo
|
|
|
|
|
|
|
|
// etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName)
|
|
|
|
|
|
|
|
// cacheClient := cacheRpc.NewCacheClient(etcdConn)
|
|
|
|
|
|
|
|
// cacheResp, err := cacheClient.GetUserInfoFromCache(context.Background(), reqCacheGetUserInfo)
|
|
|
|
|
|
|
|
// if err != nil {
|
|
|
|
|
|
|
|
// log.NewError(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed", err.Error())
|
|
|
|
|
|
|
|
// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed: " + err.Error()})
|
|
|
|
|
|
|
|
// return
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if cacheResp.CommonResp.ErrCode != 0 {
|
|
|
|
|
|
|
|
// log.NewError(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed", cacheResp.CommonResp)
|
|
|
|
|
|
|
|
// resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}}
|
|
|
|
|
|
|
|
// resp.Data = []map[string]interface{}{}
|
|
|
|
|
|
|
|
// log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp)
|
|
|
|
|
|
|
|
// c.JSON(http.StatusOK, resp)
|
|
|
|
|
|
|
|
// return
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// log.NewInfo(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "cacheResp:", cacheResp.String())
|
|
|
|
|
|
|
|
// userInfoList = cacheResp.UserInfoList
|
|
|
|
|
|
|
|
// var needCacheUserIDList []string
|
|
|
|
|
|
|
|
// for _, userID := range reqCacheGetUserInfo.UserIDList {
|
|
|
|
|
|
|
|
// isGetUserInfoFromCache := false
|
|
|
|
|
|
|
|
// for _, cacheUser := range userInfoList {
|
|
|
|
|
|
|
|
// if cacheUser.UserID == userID {
|
|
|
|
|
|
|
|
// isGetUserInfoFromCache = true
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if !isGetUserInfoFromCache {
|
|
|
|
|
|
|
|
// needCacheUserIDList = append(needCacheUserIDList, userID)
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if len(needCacheUserIDList) == 0 {
|
|
|
|
|
|
|
|
// log.NewInfo(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "get all userInfo from cache success")
|
|
|
|
|
|
|
|
// for _, v := range 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: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}, UserInfoList: publicUserInfoList}
|
|
|
|
|
|
|
|
// resp.Data = jsonData.JsonDataList(resp.UserInfoList)
|
|
|
|
|
|
|
|
// log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp)
|
|
|
|
|
|
|
|
// c.JSON(http.StatusOK, resp)
|
|
|
|
|
|
|
|
// return
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// log.NewDebug(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "need cache user list", needCacheUserIDList)
|
|
|
|
|
|
|
|
// getUserInfoReq.UserIDList = needCacheUserIDList
|
|
|
|
|
|
|
|
// 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(), getUserInfoReq)
|
|
|
|
|
|
|
|
// if err != nil {
|
|
|
|
|
|
|
|
// log.NewError(getUserInfoReq.OperationID, "GetUserInfo failed ", err.Error(), getUserInfoReq.String())
|
|
|
|
|
|
|
|
// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed" + err.Error()})
|
|
|
|
|
|
|
|
// return
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if rpcResp.CommonResp.ErrCode != 0 {
|
|
|
|
|
|
|
|
// log.NewError(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed", cacheResp.CommonResp)
|
|
|
|
|
|
|
|
// resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}}
|
|
|
|
|
|
|
|
// resp.Data = []map[string]interface{}{}
|
|
|
|
|
|
|
|
// log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp)
|
|
|
|
|
|
|
|
// c.JSON(http.StatusOK, resp)
|
|
|
|
|
|
|
|
// return
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// userInfoList = append(userInfoList, rpcResp.UserInfoList...)
|
|
|
|
|
|
|
|
// cacheUpdateUserInfoReq := &cacheRpc.UpdateUserInfoToCacheReq{
|
|
|
|
|
|
|
|
// UserInfoList: rpcResp.UserInfoList,
|
|
|
|
|
|
|
|
// OperationID: getUserInfoReq.OperationID,
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// _, err = cacheClient.UpdateUserInfoToCache(context.Background(), cacheUpdateUserInfoReq)
|
|
|
|
|
|
|
|
// if err != nil {
|
|
|
|
|
|
|
|
// log.NewError(getUserInfoReq.OperationID, "GetUserInfo failed ", err.Error())
|
|
|
|
|
|
|
|
// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed:" + err.Error()})
|
|
|
|
|
|
|
|
// return
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// userInfoList = rpcResp.UserInfoList
|
|
|
|
|
|
|
|
// for _, v := range 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(getUserInfoReq.OperationID, "GetUserInfo api return ", resp)
|
|
|
|
|
|
|
|
// c.JSON(http.StatusOK, resp)
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func GetFriendIDListFromCache(c *gin.Context) {
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
|
|
|
req api.GetFriendIDListFromCacheReq
|
|
|
|
|
|
|
|
resp api.GetFriendIDListFromCacheResp
|
|
|
|
|
|
|
|
reqPb cacheRpc.GetFriendIDListFromCacheReq
|
|
|
|
|
|
|
|
respPb *cacheRpc.GetFriendIDListFromCacheResp
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
if err := c.BindJSON(&req); err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, "BindJSON failed ", err.Error())
|
|
|
|
|
|
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()})
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(needCacheUserIDList) == 0 {
|
|
|
|
reqPb.OperationID = req.OperationID
|
|
|
|
log.NewInfo(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "get all userInfo from cache success")
|
|
|
|
var ok bool
|
|
|
|
for _, v := range userInfoList {
|
|
|
|
ok, reqPb.UserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
|
|
|
publicUserInfoList = append(publicUserInfoList,
|
|
|
|
if !ok {
|
|
|
|
&open_im_sdk.PublicUserInfo{UserID: v.UserID, Nickname: v.Nickname, FaceURL: v.FaceURL, Gender: v.Gender, Ex: v.Ex})
|
|
|
|
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
|
|
|
}
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
|
|
|
resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}, UserInfoList: publicUserInfoList}
|
|
|
|
|
|
|
|
resp.Data = jsonData.JsonDataList(resp.UserInfoList)
|
|
|
|
|
|
|
|
log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp)
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, resp)
|
|
|
|
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName)
|
|
|
|
log.NewDebug(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "need cache user list", needCacheUserIDList)
|
|
|
|
client := cacheRpc.NewCacheClient(etcdConn)
|
|
|
|
getUserInfoReq.UserIDList = needCacheUserIDList
|
|
|
|
respPb, err := client.GetFriendIDListFromCache(context.Background(), &reqPb)
|
|
|
|
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(), getUserInfoReq)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.NewError(getUserInfoReq.OperationID, "GetUserInfo failed ", err.Error(), getUserInfoReq.String())
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetFriendIDListFromCache", err.Error())
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed" + err.Error()})
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed:" + err.Error()})
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if rpcResp.CommonResp.ErrCode != 0 {
|
|
|
|
resp.UserIDList = respPb.UserIDList
|
|
|
|
log.NewError(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed", cacheResp.CommonResp)
|
|
|
|
resp.CommResp = api.CommResp{ErrMsg: respPb.CommonResp.ErrMsg, ErrCode: respPb.CommonResp.ErrCode}
|
|
|
|
resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}}
|
|
|
|
c.JSON(http.StatusOK, resp)
|
|
|
|
resp.Data = []map[string]interface{}{}
|
|
|
|
}
|
|
|
|
log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp)
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, resp)
|
|
|
|
func GetBlackIDListFromCache(c *gin.Context) {
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
|
|
|
req api.GetBlackIDListFromCacheReq
|
|
|
|
|
|
|
|
resp api.GetBlackIDListFromCacheResp
|
|
|
|
|
|
|
|
reqPb cacheRpc.GetBlackIDListFromCacheReq
|
|
|
|
|
|
|
|
respPb *cacheRpc.GetBlackIDListFromCacheResp
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
if err := c.BindJSON(&req); err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, "BindJSON failed ", err.Error())
|
|
|
|
|
|
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()})
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
userInfoList = append(userInfoList, rpcResp.UserInfoList...)
|
|
|
|
reqPb.OperationID = req.OperationID
|
|
|
|
cacheUpdateUserInfoReq := &cacheRpc.UpdateUserInfoToCacheReq{
|
|
|
|
var ok bool
|
|
|
|
UserInfoList: rpcResp.UserInfoList,
|
|
|
|
ok, reqPb.UserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
|
|
|
OperationID: getUserInfoReq.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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_, err = cacheClient.UpdateUserInfoToCache(context.Background(), cacheUpdateUserInfoReq)
|
|
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName)
|
|
|
|
|
|
|
|
client := cacheRpc.NewCacheClient(etcdConn)
|
|
|
|
|
|
|
|
respPb, err := client.GetBlackIDListFromCache(context.Background(), &reqPb)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.NewError(getUserInfoReq.OperationID, "GetUserInfo failed ", err.Error())
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetFriendIDListFromCache", err.Error())
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed:" + err.Error()})
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed:" + err.Error()})
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
userInfoList = rpcResp.UserInfoList
|
|
|
|
resp.UserIDList = respPb.UserIDList
|
|
|
|
for _, v := range userInfoList {
|
|
|
|
resp.CommResp = api.CommResp{ErrMsg: respPb.CommonResp.ErrMsg, ErrCode: respPb.CommonResp.ErrCode}
|
|
|
|
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(getUserInfoReq.OperationID, "GetUserInfo api return ", resp)
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, resp)
|
|
|
|
c.JSON(http.StatusOK, resp)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func GetUserFriendFromCache(c *gin.Context) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func GetBlackListFromCache(c *gin.Context) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func GetUsersInfo(c *gin.Context) {
|
|
|
|
func GetUsersInfo(c *gin.Context) {
|
|
|
|
params := api.GetUsersInfoReq{}
|
|
|
|
params := api.GetUsersInfoReq{}
|
|
|
|
if err := c.BindJSON(¶ms); err != nil {
|
|
|
|
if err := c.BindJSON(¶ms); err != nil {
|
|
|
@ -197,60 +293,11 @@ func UpdateUserInfo(c *gin.Context) {
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if RpcResp.CommonResp.ErrCode != 0 {
|
|
|
|
resp := api.UpdateUserInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
|
|
|
|
resp := api.UpdateUserInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
|
|
|
|
|
|
|
|
log.NewInfo(req.OperationID, "UpdateUserInfo api return ", resp)
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, resp)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var updateUserInfoReq = &cacheRpc.UpdateUserInfoToCacheReq{UserInfoList: []*open_im_sdk.UserInfo{}}
|
|
|
|
|
|
|
|
updateUserInfoReq.UserInfoList[0] = req.UserInfo
|
|
|
|
|
|
|
|
etcdConn = getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName)
|
|
|
|
|
|
|
|
cacheClient := cacheRpc.NewCacheClient(etcdConn)
|
|
|
|
|
|
|
|
cacheResp, err := cacheClient.UpdateUserInfoToCache(context.Background(), updateUserInfoReq)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, "UpdateUserInfo failed ", err.Error(), req.String())
|
|
|
|
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
resp := api.UpdateUserInfoResp{CommResp: api.CommResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}}
|
|
|
|
|
|
|
|
log.NewInfo(req.OperationID, "UpdateUserInfo api return ", resp)
|
|
|
|
log.NewInfo(req.OperationID, "UpdateUserInfo api return ", resp)
|
|
|
|
c.JSON(http.StatusOK, resp)
|
|
|
|
c.JSON(http.StatusOK, resp)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//func UpdateUserInfo(c *gin.Context) {
|
|
|
|
|
|
|
|
// params := api.UpdateSelfUserInfoReq{}
|
|
|
|
|
|
|
|
// if err := c.BindJSON(¶ms); err != nil {
|
|
|
|
|
|
|
|
// log.NewError("0", "BindJSON failed ", err.Error())
|
|
|
|
|
|
|
|
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
|
|
|
|
|
|
|
// return
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// req := &rpc.UpdateUserInfoReq{UserInfo: &open_im_sdk.UserInfo{}}
|
|
|
|
|
|
|
|
// utils.CopyStructFields(req.UserInfo, ¶ms)
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// req.OperationID = params.OperationID
|
|
|
|
|
|
|
|
// 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, "UpdateUserInfo 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.UpdateUserInfo(context.Background(), req)
|
|
|
|
|
|
|
|
// if err != nil {
|
|
|
|
|
|
|
|
// log.NewError(req.OperationID, "UpdateUserInfo failed ", err.Error(), req.String())
|
|
|
|
|
|
|
|
// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
|
|
|
|
|
|
|
// return
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// resp := api.UpdateUserInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
|
|
|
|
|
|
|
|
// log.NewInfo(req.OperationID, "UpdateUserInfo api return ", resp)
|
|
|
|
|
|
|
|
// c.JSON(http.StatusOK, resp)
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func GetSelfUserInfo(c *gin.Context) {
|
|
|
|
func GetSelfUserInfo(c *gin.Context) {
|
|
|
|
params := api.GetSelfUserInfoReq{}
|
|
|
|
params := api.GetSelfUserInfoReq{}
|
|
|
|
if err := c.BindJSON(¶ms); err != nil {
|
|
|
|
if err := c.BindJSON(¶ms); err != nil {
|
|
|
|