From a99dbf634b3064dd7174d4a3e5e4e6e4069a602a Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 4 Aug 2022 14:21:03 +0800 Subject: [PATCH] callback fix --- internal/push/logic/callback.go | 7 ++++--- internal/rpc/msg/callback.go | 6 ++++-- pkg/common/callback/callback.go | 24 ++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 pkg/common/callback/callback.go diff --git a/internal/push/logic/callback.go b/internal/push/logic/callback.go index 5c3c317bf..44f703ef8 100644 --- a/internal/push/logic/callback.go +++ b/internal/push/logic/callback.go @@ -2,6 +2,7 @@ package logic import ( cbApi "Open_IM/pkg/call_back_struct" + "Open_IM/pkg/common/callback" "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" "Open_IM/pkg/common/http" @@ -32,7 +33,7 @@ func callbackOfflinePush(operationID string, userIDList []string, msg *commonPb. ContentType: msg.ContentType, SessionType: msg.SessionType, AtUserIDList: msg.AtUserIDList, - Content: string(msg.Content), + Content: callback.GetContent(msg), } resp := &cbApi.CallbackBeforePushResp{CommonCallbackResp: &callbackResp} if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackOfflinePush.CallbackTimeOut); err != nil { @@ -74,7 +75,7 @@ func callbackOnlinePush(operationID string, userIDList []string, msg *commonPb.M ContentType: msg.ContentType, SessionType: msg.SessionType, AtUserIDList: msg.AtUserIDList, - Content: string(msg.Content), + Content: callback.GetContent(msg), } resp := &cbApi.CallbackBeforePushResp{CommonCallbackResp: &callbackResp} if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackOnlinePush.CallbackTimeOut); err != nil { @@ -110,7 +111,7 @@ func callbackBeforeSuperGroupOnlinePush(operationID string, groupID string, msg ContentType: msg.ContentType, SessionType: msg.SessionType, AtUserIDList: msg.AtUserIDList, - Content: string(msg.Content), + Content: callback.GetContent(msg), } resp := &cbApi.CallbackBeforeSuperGroupOnlinePushResp{CommonCallbackResp: &callbackResp} if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackBeforeSuperGroupOnlinePush.CallbackTimeOut); err != nil { diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index f53ee327d..ba03998a5 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -2,6 +2,7 @@ package msg import ( cbApi "Open_IM/pkg/call_back_struct" + "Open_IM/pkg/common/callback" "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" "Open_IM/pkg/common/http" @@ -12,7 +13,7 @@ import ( ) func copyCallbackCommonReqStruct(msg *pbChat.SendMsgReq) cbApi.CommonCallbackReq { - return cbApi.CommonCallbackReq{ + req := cbApi.CommonCallbackReq{ SendID: msg.MsgData.SendID, ServerMsgID: msg.MsgData.ServerMsgID, ClientMsgID: msg.MsgData.ClientMsgID, @@ -24,10 +25,11 @@ func copyCallbackCommonReqStruct(msg *pbChat.SendMsgReq) cbApi.CommonCallbackReq ContentType: msg.MsgData.ContentType, Status: msg.MsgData.Status, CreateTime: msg.MsgData.CreateTime, - Content: string(msg.MsgData.Content), AtUserIDList: msg.MsgData.AtUserIDList, SenderFaceURL: msg.MsgData.SenderFaceURL, + Content: callback.GetContent(msg.MsgData), } + return req } func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) cbApi.CommonCallbackResp { diff --git a/pkg/common/callback/callback.go b/pkg/common/callback/callback.go new file mode 100644 index 000000000..676a62a52 --- /dev/null +++ b/pkg/common/callback/callback.go @@ -0,0 +1,24 @@ +package callback + +import ( + "Open_IM/pkg/common/constant" + server_api_params "Open_IM/pkg/proto/sdk_ws" + "github.com/golang/protobuf/jsonpb" + "github.com/golang/protobuf/proto" +) + +func GetContent(msg *server_api_params.MsgData) string { + if msg.ContentType >= constant.NotificationBegin && msg.ContentType <= constant.NotificationEnd { + var tips server_api_params.TipsComm + _ = proto.Unmarshal(msg.Content, &tips) + marshaler := jsonpb.Marshaler{ + OrigName: true, + EnumsAsInts: false, + EmitDefaults: false, + } + content, _ := marshaler.MarshalToString(&tips) + return content + } else { + return string(msg.Content) + } +}