From 5f8b2790d2d7d3cf230de9ab97d2e67a906550ac Mon Sep 17 00:00:00 2001 From: Gordon <46924906+FGadvancer@users.noreply.github.com> Date: Thu, 19 Oct 2023 18:13:36 +0800 Subject: [PATCH] fix: api send messages for notification conversation . --- internal/api/msg.go | 25 +++++++------------------ internal/push/push_to_client.go | 8 +++----- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/internal/api/msg.go b/internal/api/msg.go index b9b10e98e..47aa84031 100644 --- a/internal/api/msg.go +++ b/internal/api/msg.go @@ -57,6 +57,10 @@ func (m MessageApi) newUserSendMsgReq(c *gin.Context, params *apistruct.SendMsg) var newContent string options := make(map[string]bool, 5) switch params.ContentType { + case constant.OANotification: + notification := sdkws.NotificationElem{} + notification.Detail = utils.StructToJsonString(params.Content) + newContent = utils.StructToJsonString(¬ification) case constant.Text: fallthrough case constant.Picture: @@ -69,10 +73,6 @@ func (m MessageApi) newUserSendMsgReq(c *gin.Context, params *apistruct.SendMsg) fallthrough case constant.File: fallthrough - case constant.CustomNotTriggerConversation: - fallthrough - case constant.CustomOnlineOnly: - fallthrough default: newContent = utils.StructToJsonString(params.Content) } @@ -82,11 +82,6 @@ func (m MessageApi) newUserSendMsgReq(c *gin.Context, params *apistruct.SendMsg) if params.NotOfflinePush { utils.SetSwitchFromOptions(options, constant.IsOfflinePush, false) } - if params.ContentType == constant.CustomOnlineOnly { - m.SetOptions(options, false) - } else if params.ContentType == constant.CustomNotTriggerConversation { - utils.SetSwitchFromOptions(options, constant.IsConversationUpdate, false) - } pbData := msg.SendMsgReq{ MsgData: &sdkws.MsgData{ SendID: params.SendID, @@ -105,14 +100,6 @@ func (m MessageApi) newUserSendMsgReq(c *gin.Context, params *apistruct.SendMsg) OfflinePushInfo: params.OfflinePushInfo, }, } - //if params.ContentType == constant.OANotification { - // var tips sdkws.TipsComm - // tips.JsonDetail = utils.StructToJsonString(params.Content) - // pbData.MsgData.Content, err = proto.Marshal(&tips) - // if err != nil { - // log.ZError(c, "Marshal failed ", err, "tips", tips.String()) - // } - //} return &pbData } @@ -185,6 +172,9 @@ func (m *MessageApi) getSendMsgReq(c *gin.Context, req apistruct.SendMsg) (sendM case constant.OANotification: data = apistruct.OANotificationElem{} req.SessionType = constant.NotificationChatType + if !authverify.IsManagerUserID(req.SendID) { + return nil, errs.ErrNoPermission.Wrap("only app manager can send message") + } case constant.CustomNotTriggerConversation: data = apistruct.CustomElem{} case constant.CustomOnlineOnly: @@ -212,7 +202,6 @@ func (m *MessageApi) SendMessage(c *gin.Context) { apiresp.GinError(c, errs.ErrNoPermission.Wrap("only app manager can send message")) return } - sendMsgReq, err := m.getSendMsgReq(c, req.SendMsg) if err != nil { log.ZError(c, "decodeData failed", err) diff --git a/internal/push/push_to_client.go b/internal/push/push_to_client.go index 66b003eaa..c12620f70 100644 --- a/internal/push/push_to_client.go +++ b/internal/push/push_to_client.go @@ -126,13 +126,11 @@ func (p *Pusher) Push2User(ctx context.Context, userIDs []string, msg *sdkws.Msg } func (p *Pusher) UnmarshalNotificationElem(bytes []byte, t interface{}) error { - var notificationElem struct { - Detail string `json:"detail,omitempty"` - } - if err := json.Unmarshal(bytes, ¬ificationElem); err != nil { + var notification sdkws.NotificationElem + if err := json.Unmarshal(bytes, ¬ification); err != nil { return err } - return json.Unmarshal([]byte(notificationElem.Detail), t) + return json.Unmarshal([]byte(notification.Detail), t) } func (p *Pusher) Push2SuperGroup(ctx context.Context, groupID string, msg *sdkws.MsgData) (err error) {