[MM-30980] Avoid modifying original post when sending a notification (#17697)
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3299a72adb
Коммит
42157fafa2
@@ -577,9 +577,10 @@ func (a *App) buildFullPushNotificationMessage(contentsConfig string, post *mode
|
|||||||
msg.FromWebhook = fw
|
msg.FromWebhook = fw
|
||||||
}
|
}
|
||||||
|
|
||||||
|
postMessage := post.Message
|
||||||
for _, attachment := range post.Attachments() {
|
for _, attachment := range post.Attachments() {
|
||||||
if attachment.Fallback != "" {
|
if attachment.Fallback != "" {
|
||||||
post.Message += "\n" + attachment.Fallback
|
postMessage += "\n" + attachment.Fallback
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -588,7 +589,7 @@ func (a *App) buildFullPushNotificationMessage(contentsConfig string, post *mode
|
|||||||
|
|
||||||
msg.Message = a.getPushNotificationMessage(
|
msg.Message = a.getPushNotificationMessage(
|
||||||
contentsConfig,
|
contentsConfig,
|
||||||
post.Message,
|
postMessage,
|
||||||
explicitMention,
|
explicitMention,
|
||||||
channelWideMention,
|
channelWideMention,
|
||||||
hasFiles,
|
hasFiles,
|
||||||
|
|||||||
@@ -1406,8 +1406,9 @@ func TestPushNotificationAttachment(t *testing.T) {
|
|||||||
th := Setup(t)
|
th := Setup(t)
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
|
originalMessage := "hello world"
|
||||||
post := &model.Post{
|
post := &model.Post{
|
||||||
Message: "hello world",
|
Message: originalMessage,
|
||||||
Props: map[string]interface{}{
|
Props: map[string]interface{}{
|
||||||
"attachments": []*model.SlackAttachment{
|
"attachments": []*model.SlackAttachment{
|
||||||
{
|
{
|
||||||
@@ -1421,8 +1422,14 @@ func TestPushNotificationAttachment(t *testing.T) {
|
|||||||
user := &model.User{}
|
user := &model.User{}
|
||||||
ch := &model.Channel{}
|
ch := &model.Channel{}
|
||||||
|
|
||||||
pn := th.App.buildFullPushNotificationMessage("full", post, user, ch, ch.Name, "test", false, false, "")
|
t.Run("The notification should contain the fallback message from the attachment", func(t *testing.T) {
|
||||||
assert.Equal(t, "test: hello world\nfallback text", pn.Message)
|
pn := th.App.buildFullPushNotificationMessage("full", post, user, ch, ch.Name, "test", false, false, "")
|
||||||
|
assert.Equal(t, "test: hello world\nfallback text", pn.Message)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("The original post message should not be modified", func(t *testing.T) {
|
||||||
|
assert.Equal(t, originalMessage, post.Message)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run it with | grep -v '{"level"' to prevent spamming the console.
|
// Run it with | grep -v '{"level"' to prevent spamming the console.
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user