mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
Merge remote-tracking branch 'origin/tuoyun' into tuoyun
This commit is contained in:
commit
02b09c58a1
@ -24,8 +24,9 @@ func main() {
|
|||||||
// user routing group, which handles user registration and login services
|
// user routing group, which handles user registration and login services
|
||||||
userRouterGroup := r.Group("/user")
|
userRouterGroup := r.Group("/user")
|
||||||
{
|
{
|
||||||
userRouterGroup.POST("/update_user_info", user.UpdateUserInfo) //1
|
userRouterGroup.POST("/update_user_info", user.UpdateUserInfo) //1
|
||||||
userRouterGroup.POST("/get_user_info", user.GetUserInfo) //1
|
userRouterGroup.POST("/get_user_info", user.GetUsersInfo) //1
|
||||||
|
userRouterGroup.POST("/get_self_user_info", user.GetSelfUserInfo) //1
|
||||||
}
|
}
|
||||||
//friend routing group
|
//friend routing group
|
||||||
friendRouterGroup := r.Group("/friend")
|
friendRouterGroup := r.Group("/friend")
|
||||||
|
@ -227,11 +227,11 @@ func InviteUserToGroup(c *gin.Context) {
|
|||||||
|
|
||||||
resp := api.InviteUserToGroupResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
resp := api.InviteUserToGroupResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
||||||
for _, v := range RpcResp.Id2ResultList {
|
for _, v := range RpcResp.Id2ResultList {
|
||||||
resp.UserIDResultList = append(resp.UserIDResultList, api.UserIDResult{UserID: v.UserID, Result: v.Result})
|
resp.UserIDResultList = append(resp.UserIDResultList, &api.UserIDResult{UserID: v.UserID, Result: v.Result})
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(resp.UserIDResultList) == 0 {
|
if len(resp.UserIDResultList) == 0 {
|
||||||
resp.UserIDResultList = []api.UserIDResult{}
|
resp.UserIDResultList = *new([]*api.UserIDResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.NewInfo(req.OperationID, "InviteUserToGroup api return ", resp)
|
log.NewInfo(req.OperationID, "InviteUserToGroup api return ", resp)
|
||||||
|
@ -16,8 +16,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetUserInfo(c *gin.Context) {
|
func GetUsersInfo(c *gin.Context) {
|
||||||
params := api.GetUserInfoReq{}
|
params := api.GetUsersInfoReq{}
|
||||||
if err := c.BindJSON(¶ms); err != nil {
|
if err := c.BindJSON(¶ms); err != nil {
|
||||||
log.NewError("0", "BindJSON failed ", err.Error())
|
log.NewError("0", "BindJSON failed ", err.Error())
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()})
|
||||||
@ -42,15 +42,20 @@ func GetUserInfo(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
|
||||||
}
|
}
|
||||||
|
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, AppMangerLevel: v.AppMangerLevel})
|
||||||
|
}
|
||||||
|
|
||||||
resp := api.GetUserInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, UserInfoList: RpcResp.UserInfoList}
|
resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, UserInfoList: publicUserInfoList}
|
||||||
resp.Data = jsonData.JsonDataList(resp.UserInfoList)
|
resp.Data = jsonData.JsonDataList(resp.UserInfoList)
|
||||||
log.NewInfo(req.OperationID, "GetUserInfo api return ", resp)
|
log.NewInfo(req.OperationID, "GetUserInfo api return ", resp)
|
||||||
c.JSON(http.StatusOK, resp)
|
c.JSON(http.StatusOK, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateUserInfo(c *gin.Context) {
|
func UpdateUserInfo(c *gin.Context) {
|
||||||
params := api.UpdateUserInfoReq{}
|
params := api.UpdateSelfUserInfoReq{}
|
||||||
if err := c.BindJSON(¶ms); err != nil {
|
if err := c.BindJSON(¶ms); err != nil {
|
||||||
log.NewError("0", "BindJSON failed ", err.Error())
|
log.NewError("0", "BindJSON failed ", err.Error())
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
@ -80,3 +85,45 @@ func UpdateUserInfo(c *gin.Context) {
|
|||||||
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 GetSelfUserInfo(c *gin.Context) {
|
||||||
|
params := api.GetSelfUserInfoReq{}
|
||||||
|
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"))
|
||||||
|
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
|
||||||
|
}
|
||||||
|
req.UserIDList = append(req.UserIDList, req.OpUserID)
|
||||||
|
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
|
||||||
|
}
|
||||||
|
if len(RpcResp.UserInfoList) == 1 {
|
||||||
|
resp := api.GetSelfUserInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, UserInfoList: RpcResp.UserInfoList[0]}
|
||||||
|
resp.Data = jsonData.JsonDataList(resp.UserInfoList)
|
||||||
|
log.NewInfo(req.OperationID, "GetUserInfo api return ", resp)
|
||||||
|
c.JSON(http.StatusOK, resp)
|
||||||
|
} else {
|
||||||
|
resp := api.GetSelfUserInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
|
||||||
|
resp.Data = jsonData.JsonDataList(resp.UserInfoList)
|
||||||
|
log.NewInfo(req.OperationID, "GetUserInfo api return ", resp)
|
||||||
|
c.JSON(http.StatusOK, resp)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -171,7 +171,7 @@ func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJo
|
|||||||
group, err := imdb.GetGroupInfoByGroupID(v)
|
group, err := imdb.GetGroupInfoByGroupID(v)
|
||||||
if num > 0 && owner != nil && err2 == nil && group != nil && err == nil {
|
if num > 0 && owner != nil && err2 == nil && group != nil && err == nil {
|
||||||
utils.CopyStructFields(&groupNode, group)
|
utils.CopyStructFields(&groupNode, group)
|
||||||
groupNode.CreateTime = group.CreateTime.Unix()
|
groupNode.CreateTime = uint32(group.CreateTime.Unix())
|
||||||
groupNode.MemberCount = uint32(num)
|
groupNode.MemberCount = uint32(num)
|
||||||
groupNode.OwnerUserID = owner.UserID
|
groupNode.OwnerUserID = owner.UserID
|
||||||
resp.GroupList = append(resp.GroupList, &groupNode)
|
resp.GroupList = append(resp.GroupList, &groupNode)
|
||||||
|
@ -45,7 +45,7 @@ type InviteUserToGroupReq struct {
|
|||||||
}
|
}
|
||||||
type InviteUserToGroupResp struct {
|
type InviteUserToGroupResp struct {
|
||||||
CommResp
|
CommResp
|
||||||
UserIDResultList []UserIDResult `json:"data"`
|
UserIDResultList []*UserIDResult `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetJoinedGroupListReq struct {
|
type GetJoinedGroupListReq struct {
|
||||||
|
@ -4,17 +4,17 @@ import (
|
|||||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetUserInfoReq struct {
|
type GetUsersInfoReq struct {
|
||||||
OperationID string `json:"operationID" binding:"required"`
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
UserIDList []string `json:"userIDList" binding:"required"`
|
UserIDList []string `json:"userIDList" binding:"required"`
|
||||||
}
|
}
|
||||||
type GetUserInfoResp struct {
|
type GetUsersInfoResp struct {
|
||||||
CommResp
|
CommResp
|
||||||
UserInfoList []*open_im_sdk.UserInfo `json:"-"`
|
UserInfoList []*open_im_sdk.PublicUserInfo
|
||||||
Data []map[string]interface{} `json:"data"`
|
Data []map[string]interface{} `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateUserInfoReq struct {
|
type UpdateSelfUserInfoReq struct {
|
||||||
UserInfo
|
UserInfo
|
||||||
OperationID string `json:"operationID" binding:"required"`
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
}
|
}
|
||||||
@ -22,3 +22,13 @@ type UpdateUserInfoReq struct {
|
|||||||
type UpdateUserInfoResp struct {
|
type UpdateUserInfoResp struct {
|
||||||
CommResp
|
CommResp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetSelfUserInfoReq struct {
|
||||||
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
UserID string `json:"userID" binding:"required"`
|
||||||
|
}
|
||||||
|
type GetSelfUserInfoResp struct {
|
||||||
|
CommResp
|
||||||
|
UserInfoList *open_im_sdk.UserInfo `json:"-"`
|
||||||
|
Data []map[string]interface{} `json:"data"`
|
||||||
|
}
|
||||||
|
@ -92,7 +92,7 @@ func DeleteGroupMemberByGroupIDAndUserID(groupID, userID string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = dbConn.Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Delete(&db.GroupMember{}).Error
|
err = dbConn.Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Delete(db.GroupMember{}).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ func DelGroupRequestByGroupIDAndUserID(groupID, userID string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = dbConn.Table("group_requests").Where("group_id=? and user_id=?", groupID, userID).Delete(&db.GroupRequest{}).Error
|
err = dbConn.Table("group_requests").Where("group_id=? and user_id=?", groupID, userID).Delete(db.GroupRequest{}).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user