From 29dbb369613dd397ff8847e607bd4d9c44b0cf90 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Thu, 16 Jun 2022 19:33:35 +0800 Subject: [PATCH] user proto modify --- cmd/open_im_api/main.go | 3 ++- internal/api/user/user.go | 38 ++++++++++++++++++++++++++++++++ internal/rpc/user/user.go | 21 ++++++++++++++++++ pkg/base_info/user_api_struct.go | 8 ++++++- script/start_all.sh | 2 +- 5 files changed, 69 insertions(+), 3 deletions(-) diff --git a/cmd/open_im_api/main.go b/cmd/open_im_api/main.go index e8cf2e799..8b3818aa8 100644 --- a/cmd/open_im_api/main.go +++ b/cmd/open_im_api/main.go @@ -38,7 +38,8 @@ func main() { // user routing group, which handles user registration and login services userRouterGroup := r.Group("/user") { - userRouterGroup.POST("/update_user_info", user.UpdateUserInfo) //1 + userRouterGroup.POST("/update_user_info", user.UpdateUserInfo) //1 + userRouterGroup.POST("/set_global_msg_recv_opt", user.SetGlobalRecvMessageOpt) 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 diff --git a/internal/api/user/user.go b/internal/api/user/user.go index af93416b4..ac40059d3 100644 --- a/internal/api/user/user.go +++ b/internal/api/user/user.go @@ -233,6 +233,44 @@ func UpdateUserInfo(c *gin.Context) { log.NewInfo(req.OperationID, "UpdateUserInfo api return ", resp) c.JSON(http.StatusOK, resp) } +func SetGlobalRecvMessageOpt(c *gin.Context) { + params := api.SetGlobalRecvMessageOptReq{} + 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.SetGlobalRecvMessageOptReq{} + utils.CopyStructFields(req, ¶ms) + req.OperationID = params.OperationID + var ok bool + var errInfo string + ok, req.UserID, errInfo = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID) + if !ok { + errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token") + log.NewError(req.OperationID, errMsg) + c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg}) + return + } + log.NewInfo(params.OperationID, "SetGlobalRecvMessageOpt args ", req.String()) + etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, req.OperationID) + if etcdConn == nil { + errMsg := req.OperationID + "getcdv3.GetConn == nil" + log.NewError(req.OperationID, errMsg) + c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg}) + return + } + client := rpc.NewUserClient(etcdConn) + RpcResp, err := client.SetGlobalRecvMessageOpt(context.Background(), req) + if err != nil { + log.NewError(req.OperationID, "SetGlobalRecvMessageOpt 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, "SetGlobalRecvMessageOpt api return ", resp) + c.JSON(http.StatusOK, resp) +} func GetSelfUserInfo(c *gin.Context) { params := api.GetSelfUserInfoReq{} diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go index 86bd07c5b..fa733cbe4 100644 --- a/internal/rpc/user/user.go +++ b/internal/rpc/user/user.go @@ -433,7 +433,28 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI //} return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{}}, nil } +func (s *userServer) SetGlobalRecvMessageOpt(ctx context.Context, req *pbUser.SetGlobalRecvMessageOptReq) (*pbUser.SetGlobalRecvMessageOptResp, error) { + log.NewInfo(req.OperationID, "SetGlobalRecvMessageOpt args ", req.String()) + var user db.User + user.UserID = req.UserID + m := make(map[string]interface{}, 1) + + log.NewDebug(req.OperationID, utils.GetSelfFuncName(), req.GlobalRecvMsgOpt, "set GlobalRecvMsgOpt") + m["global_recv_msg_opt"] = req.GlobalRecvMsgOpt + err := db.DB.SetUserGlobalMsgRecvOpt(user.UserID, req.GlobalRecvMsgOpt) + if err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetGlobalRecvMessageOpt failed ", err.Error(), user) + return &pbUser.SetGlobalRecvMessageOptResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil + } + err = imdb.UpdateUserInfoByMap(user, m) + if err != nil { + log.NewError(req.OperationID, "SetGlobalRecvMessageOpt failed ", err.Error(), user) + return &pbUser.SetGlobalRecvMessageOptResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil + } + chat.UserInfoUpdatedNotification(req.OperationID, req.UserID, req.UserID) + return &pbUser.SetGlobalRecvMessageOptResp{CommonResp: &pbUser.CommonResp{}}, nil +} func (s *userServer) SyncJoinedGroupMemberFaceURL(userID string, faceURL string, operationID string, opUserID string) { joinedGroupIDList, err := imdb.GetJoinedGroupIDListByUserID(userID) if err != nil { diff --git a/pkg/base_info/user_api_struct.go b/pkg/base_info/user_api_struct.go index b517f24de..45c8cb22d 100644 --- a/pkg/base_info/user_api_struct.go +++ b/pkg/base_info/user_api_struct.go @@ -18,7 +18,13 @@ type UpdateSelfUserInfoReq struct { ApiUserInfo OperationID string `json:"operationID" binding:"required"` } - +type SetGlobalRecvMessageOptReq struct { + OperationID string `json:"operationID" binding:"required"` + GlobalRecvMsgOpt *int32 `json:"globalRecvMsgOpt" binding:"omitempty,oneof=0 1 2"` +} +type SetGlobalRecvMessageOptResp struct { + CommResp +} type UpdateUserInfoResp struct { CommResp } diff --git a/script/start_all.sh b/script/start_all.sh index bf7170d68..9fcbd1c6a 100644 --- a/script/start_all.sh +++ b/script/start_all.sh @@ -5,10 +5,10 @@ #fixme Put the shell script name here need_to_start_server_shell=( start_rpc_service.sh - msg_gateway_start.sh push_start.sh msg_transfer_start.sh sdk_svr_start.sh + msg_gateway_start.sh demo_svr_start.sh ) time=`date +"%Y-%m-%d %H:%M:%S"`