From 4d56dfdfa29813ec7df55b9daf6219fb2f7a8463 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 9 Dec 2022 12:13:14 +0800 Subject: [PATCH] modify --- cmd/open_im_api/main.go | 5 + config/config.yaml | 3 +- internal/api/msg/extend_msg.go | 206 ++++++++++++++++++++++++ internal/rpc/msg/callback.go | 6 - internal/rpc/msg/extend_msg_callback.go | 9 ++ pkg/base_info/msg.go | 61 ++++++- 6 files changed, 278 insertions(+), 12 deletions(-) create mode 100644 internal/api/msg/extend_msg.go create mode 100644 internal/rpc/msg/extend_msg_callback.go diff --git a/cmd/open_im_api/main.go b/cmd/open_im_api/main.go index 94cb88831..074028eec 100644 --- a/cmd/open_im_api/main.go +++ b/cmd/open_im_api/main.go @@ -163,6 +163,11 @@ func main() { chatGroup.POST("/batch_send_msg", manage.ManagementBatchSendMsg) chatGroup.POST("/check_msg_is_send_success", manage.CheckMsgIsSendSuccess) chatGroup.POST("/set_msg_min_seq", apiChat.SetMsgMinSeq) + + chatGroup.POST("/set_message_reaction_extensions", apiChat.SetMessageReactionExtensions) + chatGroup.POST("/get_message_list_reaction_extensions", apiChat.GetMessageListReactionExtensions) + chatGroup.POST("/add_message_reaction_extensions", apiChat.AddMessageReactionExtensions) + chatGroup.POST("/delete_message_reaction_extensions", apiChat.DeleteMessageReactionExtensions) } //Conversation conversationGroup := r.Group("/conversation") diff --git a/config/config.yaml b/config/config.yaml index 966c613f4..9d452e0e1 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -345,11 +345,12 @@ callback: enable: false callbackTimeOut: 2 callbackFailedContinue: true # 回调超时是否继续 - callbackBeforeExtendMsgModify: + callbackSetMessageReactionExtensions: enable: false callbackTimeOut: 2 callbackFailedContinue: true # 回调超时是否继续 + notification: groupCreated: conversation: diff --git a/internal/api/msg/extend_msg.go b/internal/api/msg/extend_msg.go new file mode 100644 index 000000000..1d6b8db07 --- /dev/null +++ b/internal/api/msg/extend_msg.go @@ -0,0 +1,206 @@ +package msg + +import ( + api "Open_IM/pkg/base_info" + "Open_IM/pkg/common/config" + "Open_IM/pkg/common/constant" + "Open_IM/pkg/common/log" + "Open_IM/pkg/common/token_verify" + "Open_IM/pkg/grpc-etcdv3/getcdv3" + rpc "Open_IM/pkg/proto/msg" + "Open_IM/pkg/utils" + "context" + "github.com/gin-gonic/gin" + "net/http" + "strings" +) + +func SetMessageReactionExtensions(c *gin.Context) { + var ( + req api.SetMessageReactionExtensionsCallbackReq + resp api.SetMessageReactionExtensionsCallbackResp + reqPb rpc.ModifyMessageReactionExtensionsReq + ) + + if err := c.BindJSON(&req); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()}) + return + } + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req) + + if err := utils.CopyStructFields(&reqPb, &req); err != nil { + log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields", err.Error()) + } + var ok bool + var errInfo string + ok, reqPb.OpUserID, 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.StatusBadRequest, gin.H{"errCode": 500, "errMsg": errMsg}) + return + } + + grpcConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, req.OperationID) + if grpcConn == nil { + errMsg := req.OperationID + " getcdv3.GetDefaultConn == nil" + log.NewError(req.OperationID, errMsg) + c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg}) + return + } + msgClient := rpc.NewMsgClient(grpcConn) + respPb, err := msgClient.SetMessageReactionExtensions(context.Background(), &reqPb) + if err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "DelMsgList failed", err.Error(), reqPb) + c.JSON(http.StatusOK, gin.H{"errCode": constant.ErrServer.ErrCode, "errMsg": constant.ErrServer.ErrMsg + err.Error()}) + return + } + resp.ErrCode = respPb.ErrCode + resp.ErrMsg = respPb.ErrMsg + resp.FailedList = respPb.FailedList + resp.SuccessList = respPb.SuccessList + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp) + c.JSON(http.StatusOK, resp) + +} + +func GetMessageListReactionExtensions(c *gin.Context) { + var ( + req api.GetMessageListReactionExtensionsReq + resp api.GetMessageListReactionExtensionsResp + reqPb rpc.OperateMessageListReactionExtensionsReq + ) + if err := c.BindJSON(&req); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()}) + return + } + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req) + + if err := utils.CopyStructFields(&reqPb, &req); err != nil { + log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields", err.Error()) + } + var ok bool + var errInfo string + ok, reqPb.OpUserID, 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.StatusBadRequest, gin.H{"errCode": 500, "errMsg": errMsg}) + return + } + + grpcConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, req.OperationID) + if grpcConn == nil { + errMsg := req.OperationID + " getcdv3.GetDefaultConn == nil" + log.NewError(req.OperationID, errMsg) + c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg}) + return + } + msgClient := rpc.NewMsgClient(grpcConn) + respPb, err := msgClient.GetMessageListReactionExtensions(context.Background(), &reqPb) + if err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "DelMsgList failed", err.Error(), reqPb) + c.JSON(http.StatusOK, gin.H{"errCode": constant.ErrServer.ErrCode, "errMsg": constant.ErrServer.ErrMsg + err.Error()}) + return + } + resp.ErrCode = respPb.ErrCode + resp.ErrMsg = respPb.ErrMsg + resp.FailedList = respPb.FailedList + resp.SuccessList = respPb.SuccessList + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp) + c.JSON(http.StatusOK, resp) +} + +func AddMessageReactionExtensions(c *gin.Context) { + var ( + req api.AddMessageReactionExtensionsReq + resp api.AddMessageReactionExtensionsResp + reqPb rpc.ModifyMessageReactionExtensionsReq + ) + if err := c.BindJSON(&req); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()}) + return + } + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req) + + if err := utils.CopyStructFields(&reqPb, &req); err != nil { + log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields", err.Error()) + } + var ok bool + var errInfo string + ok, reqPb.OpUserID, 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.StatusBadRequest, gin.H{"errCode": 500, "errMsg": errMsg}) + return + } + + grpcConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, req.OperationID) + if grpcConn == nil { + errMsg := req.OperationID + " getcdv3.GetDefaultConn == nil" + log.NewError(req.OperationID, errMsg) + c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg}) + return + } + msgClient := rpc.NewMsgClient(grpcConn) + respPb, err := msgClient.AddMessageReactionExtensions(context.Background(), &reqPb) + if err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "DelMsgList failed", err.Error(), reqPb) + c.JSON(http.StatusOK, gin.H{"errCode": constant.ErrServer.ErrCode, "errMsg": constant.ErrServer.ErrMsg + err.Error()}) + return + } + resp.ErrCode = respPb.ErrCode + resp.ErrMsg = respPb.ErrMsg + resp.FailedList = respPb.FailedList + resp.SuccessList = respPb.SuccessList + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp) + c.JSON(http.StatusOK, resp) +} + +func DeleteMessageReactionExtensions(c *gin.Context) { + var ( + req api.DeleteMessageReactionExtensionsReq + resp api.DeleteMessageReactionExtensionsResp + reqPb rpc.OperateMessageListReactionExtensionsReq + ) + if err := c.BindJSON(&req); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()}) + return + } + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req) + + if err := utils.CopyStructFields(&reqPb, &req); err != nil { + log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields", err.Error()) + } + var ok bool + var errInfo string + ok, reqPb.OpUserID, 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.StatusBadRequest, gin.H{"errCode": 500, "errMsg": errMsg}) + return + } + + grpcConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, req.OperationID) + if grpcConn == nil { + errMsg := req.OperationID + " getcdv3.GetDefaultConn == nil" + log.NewError(req.OperationID, errMsg) + c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg}) + return + } + msgClient := rpc.NewMsgClient(grpcConn) + respPb, err := msgClient.DeleteMessageReactionExtensions(context.Background(), &reqPb) + if err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "DelMsgList failed", err.Error(), reqPb) + c.JSON(http.StatusOK, gin.H{"errCode": constant.ErrServer.ErrCode, "errMsg": constant.ErrServer.ErrMsg + err.Error()}) + return + } + resp.ErrCode = respPb.ErrCode + resp.ErrMsg = respPb.ErrMsg + resp.FailedList = respPb.FailedList + resp.SuccessList = respPb.SuccessList + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp) + c.JSON(http.StatusOK, resp) +} diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index b4ae38418..5fae1e133 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -221,9 +221,3 @@ func callbackMsgModify(msg *pbChat.SendMsgReq) cbApi.CommonCallbackResp { log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), string(msg.MsgData.Content)) return callbackResp } - -func CallbackBeforeExtendMsgModify() cbApi.CommonCallbackResp { - callbackResp := cbApi.CommonCallbackResp{OperationID: ""} - - return callbackResp -} diff --git a/internal/rpc/msg/extend_msg_callback.go b/internal/rpc/msg/extend_msg_callback.go new file mode 100644 index 000000000..956c86c9d --- /dev/null +++ b/internal/rpc/msg/extend_msg_callback.go @@ -0,0 +1,9 @@ +package msg + +func callbackSetMessageReactionExtensions() { + +} + +func callbackDeleteMessageReactionExtensions() { + +} diff --git a/pkg/base_info/msg.go b/pkg/base_info/msg.go index 2b12a2b2e..4e27873b7 100644 --- a/pkg/base_info/msg.go +++ b/pkg/base_info/msg.go @@ -1,5 +1,10 @@ package base_info +import ( + "Open_IM/pkg/proto/msg" + sdk_ws "Open_IM/pkg/proto/sdk_ws" +) + type DelMsgReq struct { UserID string `json:"userID,omitempty" binding:"required"` SeqList []uint32 `json:"seqList,omitempty" binding:"required"` @@ -18,6 +23,7 @@ type CleanUpMsgReq struct { type CleanUpMsgResp struct { CommResp } + type DelSuperGroupMsgReq struct { UserID string `json:"userID" binding:"required"` GroupID string `json:"groupID" binding:"required"` @@ -29,23 +35,68 @@ type DelSuperGroupMsgReq struct { type DelSuperGroupMsgResp struct { CommResp } + type MsgDeleteNotificationElem struct { GroupID string `json:"groupID"` IsAllDelete bool `json:"isAllDelete"` SeqList []uint32 `json:"seqList"` } -//UserID string `protobuf:"bytes,1,opt,name=userID" json:"userID,omitempty"` -// GroupID string `protobuf:"bytes,2,opt,name=groupID" json:"groupID,omitempty"` -// MinSeq uint32 `protobuf:"varint,3,opt,name=minSeq" json:"minSeq,omitempty"` -// OperationID string `protobuf:"bytes,4,opt,name=operationID" json:"operationID,omitempty"` -// OpUserID string `protobuf:"bytes,5,opt,name=opUserID" json:"opUserID,omitempty"` type SetMsgMinSeqReq struct { UserID string `json:"userID" binding:"required"` GroupID string `json:"groupID"` MinSeq uint32 `json:"minSeq" binding:"required"` OperationID string `json:"operationID" binding:"required"` } + type SetMsgMinSeqResp struct { CommResp } + +type ModifyMessageReactionExtensionsReq struct { + OperationID string `json:"operationID" binding:"required"` + SourceID string `json:"sourceID" binding:"required"` + SessionType int32 `json:"sessionType" binding:"required"` + ReactionExtensionList map[string]*sdk_ws.KeyValue `json:"reactionExtensionList,omitempty" binding:"required"` + ClientMsgID string `json:"clientMsgID" binding:"required"` + Ex *string `json:"ex"` + AttachedInfo *string `json:"attachedInfo"` + IsReact bool `json:"isReact"` + IsExternalExtensions bool `json:"isExternalExtensions"` + MsgFirstModifyTime int64 `json:"msgFirstModifyTime"` +} + +type ModifyMessageReactionExtensionsResp struct { + CommResp + SuccessList []*sdk_ws.ExtendMsg `json:"successList"` + FailedList []*sdk_ws.ExtendMsg `json:"failedList"` +} + +type OperateMessageListReactionExtensionsReq struct { + OperationID string `json:"operationID" binding:"required"` + SourceID string `json:"sourceID" binding:"required"` + SessionType string `json:"sessionType" binding:"required"` + MessageReactionKeyList []*msg.OperateMessageListReactionExtensionsReq_MessageReactionKey `json:"messageReactionKeyList" binding:"required"` +} + +type OperateMessageListReactionExtensionsResp struct { + CommResp + SuccessList []*sdk_ws.ExtendMsg `json:"successList"` + FailedList []*sdk_ws.ExtendMsg `json:"failedList"` +} + +type SetMessageReactionExtensionsCallbackReq ModifyMessageReactionExtensionsReq + +type SetMessageReactionExtensionsCallbackResp ModifyMessageReactionExtensionsResp + +type GetMessageListReactionExtensionsReq OperateMessageListReactionExtensionsReq + +type GetMessageListReactionExtensionsResp OperateMessageListReactionExtensionsResp + +type AddMessageReactionExtensionsReq ModifyMessageReactionExtensionsReq + +type AddMessageReactionExtensionsResp ModifyMessageReactionExtensionsResp + +type DeleteMessageReactionExtensionsReq OperateMessageListReactionExtensionsReq + +type DeleteMessageReactionExtensionsResp OperateMessageListReactionExtensionsResp