diff --git a/app/notification_push.go b/app/notification_push.go index 45d608baac..d7fbc739fa 100644 --- a/app/notification_push.go +++ b/app/notification_push.go @@ -577,9 +577,10 @@ func (a *App) buildFullPushNotificationMessage(contentsConfig string, post *mode msg.FromWebhook = fw } + postMessage := post.Message for _, attachment := range post.Attachments() { 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( contentsConfig, - post.Message, + postMessage, explicitMention, channelWideMention, hasFiles, diff --git a/app/notification_push_test.go b/app/notification_push_test.go index 28dd6f195f..32b6f1be89 100644 --- a/app/notification_push_test.go +++ b/app/notification_push_test.go @@ -1406,8 +1406,9 @@ func TestPushNotificationAttachment(t *testing.T) { th := Setup(t) defer th.TearDown() + originalMessage := "hello world" post := &model.Post{ - Message: "hello world", + Message: originalMessage, Props: map[string]interface{}{ "attachments": []*model.SlackAttachment{ { @@ -1421,8 +1422,14 @@ func TestPushNotificationAttachment(t *testing.T) { user := &model.User{} ch := &model.Channel{} - 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 notification should contain the fallback message from the attachment", func(t *testing.T) { + 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.