From 446c6d452e01afc3576e40a1454d9acda22f1cfc Mon Sep 17 00:00:00 2001 From: Sheshagiri Rao Mallipedhi Date: Tue, 23 Apr 2019 21:50:19 +0530 Subject: [PATCH] MM-12795: remove @ from push notifications (#10298) * remove @ from push notifications * prepend @ when display name is set to username * fix @ in username * fix username getting prefixed in push notifications --- app/notification_push.go | 18 +++++---- app/notification_push_test.go | 76 +++++++++++++++++------------------ 2 files changed, 49 insertions(+), 45 deletions(-) diff --git a/app/notification_push.go b/app/notification_push.go index e308a9ca97..cf732fb0de 100644 --- a/app/notification_push.go +++ b/app/notification_push.go @@ -133,6 +133,10 @@ func (a *App) sendPushNotification(notification *postNotification, user *model.U channelName := notification.GetChannelName(nameFormat, user.Id) senderName := notification.GetSenderName(nameFormat, *cfg.ServiceSettings.EnablePostUsernameOverride) + if senderName == notification.sender.Username { + senderName = "@" + senderName + } + c := a.Srv.PushNotificationsHub.GetGoChannelFromUserId(user.Id) c <- PushNotification{ notificationType: NOTIFICATION_TYPE_MESSAGE, @@ -155,7 +159,7 @@ func (a *App) getPushNotificationMessage(postMessage string, explicitMention, ch if channelType == model.CHANNEL_DIRECT { return strings.Trim(userLocale("api.post.send_notifications_and_forget.push_image_only"), " ") } - return "@" + senderName + userLocale("api.post.send_notifications_and_forget.push_image_only") + return senderName + userLocale("api.post.send_notifications_and_forget.push_image_only") } contentsConfig := *a.Config().EmailSettings.PushNotificationContents @@ -164,7 +168,7 @@ func (a *App) getPushNotificationMessage(postMessage string, explicitMention, ch if channelType == model.CHANNEL_DIRECT { return model.ClearMentionTags(postMessage) } - return "@" + senderName + ": " + model.ClearMentionTags(postMessage) + return senderName + ": " + model.ClearMentionTags(postMessage) } if channelType == model.CHANNEL_DIRECT { @@ -172,22 +176,22 @@ func (a *App) getPushNotificationMessage(postMessage string, explicitMention, ch } if channelWideMention { - return "@" + senderName + userLocale("api.post.send_notification_and_forget.push_channel_mention") + return senderName + userLocale("api.post.send_notification_and_forget.push_channel_mention") } if explicitMention { - return "@" + senderName + userLocale("api.post.send_notifications_and_forget.push_explicit_mention") + return senderName + userLocale("api.post.send_notifications_and_forget.push_explicit_mention") } if replyToThreadType == THREAD_ROOT { - return "@" + senderName + userLocale("api.post.send_notification_and_forget.push_comment_on_post") + return senderName + userLocale("api.post.send_notification_and_forget.push_comment_on_post") } if replyToThreadType == THREAD_ANY { - return "@" + senderName + userLocale("api.post.send_notification_and_forget.push_comment_on_thread") + return senderName + userLocale("api.post.send_notification_and_forget.push_comment_on_thread") } - return "@" + senderName + userLocale("api.post.send_notifications_and_forget.push_general_message") + return senderName + userLocale("api.post.send_notifications_and_forget.push_general_message") } func (a *App) ClearPushNotificationSync(currentSessionId, userId, channelId string) { diff --git a/app/notification_push_test.go b/app/notification_push_test.go index cfa47ae9f0..a7a7cf36d0 100644 --- a/app/notification_push_test.go +++ b/app/notification_push_test.go @@ -555,77 +555,77 @@ func TestGetPushNotificationMessage(t *testing.T) { "full message, public channel, no mention": { Message: "this is a message", ChannelType: model.CHANNEL_OPEN, - ExpectedMessage: "@user: this is a message", + ExpectedMessage: "user: this is a message", }, "full message, public channel, mention": { Message: "this is a message", explicitMention: true, ChannelType: model.CHANNEL_OPEN, - ExpectedMessage: "@user: this is a message", + ExpectedMessage: "user: this is a message", }, "full message, public channel, channel wide mention": { Message: "this is a message", channelWideMention: true, ChannelType: model.CHANNEL_OPEN, - ExpectedMessage: "@user: this is a message", + ExpectedMessage: "user: this is a message", }, "full message, public channel, commented on post": { Message: "this is a message", replyToThreadType: THREAD_ROOT, ChannelType: model.CHANNEL_OPEN, - ExpectedMessage: "@user: this is a message", + ExpectedMessage: "user: this is a message", }, "full message, public channel, commented on thread": { Message: "this is a message", replyToThreadType: THREAD_ANY, ChannelType: model.CHANNEL_OPEN, - ExpectedMessage: "@user: this is a message", + ExpectedMessage: "user: this is a message", }, "full message, private channel, no mention": { Message: "this is a message", ChannelType: model.CHANNEL_PRIVATE, - ExpectedMessage: "@user: this is a message", + ExpectedMessage: "user: this is a message", }, "full message, private channel, mention": { Message: "this is a message", explicitMention: true, ChannelType: model.CHANNEL_PRIVATE, - ExpectedMessage: "@user: this is a message", + ExpectedMessage: "user: this is a message", }, "full message, private channel, commented on post": { Message: "this is a message", replyToThreadType: THREAD_ROOT, ChannelType: model.CHANNEL_PRIVATE, - ExpectedMessage: "@user: this is a message", + ExpectedMessage: "user: this is a message", }, "full message, private channel, commented on thread": { Message: "this is a message", replyToThreadType: THREAD_ANY, ChannelType: model.CHANNEL_PRIVATE, - ExpectedMessage: "@user: this is a message", + ExpectedMessage: "user: this is a message", }, "full message, group message channel, no mention": { Message: "this is a message", ChannelType: model.CHANNEL_GROUP, - ExpectedMessage: "@user: this is a message", + ExpectedMessage: "user: this is a message", }, "full message, group message channel, mention": { Message: "this is a message", explicitMention: true, ChannelType: model.CHANNEL_GROUP, - ExpectedMessage: "@user: this is a message", + ExpectedMessage: "user: this is a message", }, "full message, group message channel, commented on post": { Message: "this is a message", replyToThreadType: THREAD_ROOT, ChannelType: model.CHANNEL_GROUP, - ExpectedMessage: "@user: this is a message", + ExpectedMessage: "user: this is a message", }, "full message, group message channel, commented on thread": { Message: "this is a message", replyToThreadType: THREAD_ANY, ChannelType: model.CHANNEL_GROUP, - ExpectedMessage: "@user: this is a message", + ExpectedMessage: "user: this is a message", }, "full message, direct message channel, no mention": { Message: "this is a message", @@ -654,103 +654,103 @@ func TestGetPushNotificationMessage(t *testing.T) { Message: "this is a message", PushNotificationContents: model.GENERIC_NOTIFICATION, ChannelType: model.CHANNEL_OPEN, - ExpectedMessage: "@user posted a message.", + ExpectedMessage: "user posted a message.", }, "generic message with channel, public channel, mention": { Message: "this is a message", explicitMention: true, PushNotificationContents: model.GENERIC_NOTIFICATION, ChannelType: model.CHANNEL_OPEN, - ExpectedMessage: "@user mentioned you.", + ExpectedMessage: "user mentioned you.", }, "generic message with channel, public channel, channel wide mention": { Message: "this is a message", channelWideMention: true, PushNotificationContents: model.GENERIC_NOTIFICATION, ChannelType: model.CHANNEL_OPEN, - ExpectedMessage: "@user notified the channel.", + ExpectedMessage: "user notified the channel.", }, "generic message, public channel, commented on post": { Message: "this is a message", replyToThreadType: THREAD_ROOT, PushNotificationContents: model.GENERIC_NOTIFICATION, ChannelType: model.CHANNEL_OPEN, - ExpectedMessage: "@user commented on your post.", + ExpectedMessage: "user commented on your post.", }, "generic message, public channel, commented on thread": { Message: "this is a message", replyToThreadType: THREAD_ANY, PushNotificationContents: model.GENERIC_NOTIFICATION, ChannelType: model.CHANNEL_OPEN, - ExpectedMessage: "@user commented on a thread you participated in.", + ExpectedMessage: "user commented on a thread you participated in.", }, "generic message with channel, private channel, no mention": { Message: "this is a message", PushNotificationContents: model.GENERIC_NOTIFICATION, ChannelType: model.CHANNEL_PRIVATE, - ExpectedMessage: "@user posted a message.", + ExpectedMessage: "user posted a message.", }, "generic message with channel, private channel, mention": { Message: "this is a message", explicitMention: true, PushNotificationContents: model.GENERIC_NOTIFICATION, ChannelType: model.CHANNEL_PRIVATE, - ExpectedMessage: "@user mentioned you.", + ExpectedMessage: "user mentioned you.", }, "generic message with channel, private channel, channel wide mention": { Message: "this is a message", channelWideMention: true, PushNotificationContents: model.GENERIC_NOTIFICATION, ChannelType: model.CHANNEL_PRIVATE, - ExpectedMessage: "@user notified the channel.", + ExpectedMessage: "user notified the channel.", }, "generic message, public private, commented on post": { Message: "this is a message", replyToThreadType: THREAD_ROOT, PushNotificationContents: model.GENERIC_NOTIFICATION, ChannelType: model.CHANNEL_PRIVATE, - ExpectedMessage: "@user commented on your post.", + ExpectedMessage: "user commented on your post.", }, "generic message, public private, commented on thread": { Message: "this is a message", replyToThreadType: THREAD_ANY, PushNotificationContents: model.GENERIC_NOTIFICATION, ChannelType: model.CHANNEL_PRIVATE, - ExpectedMessage: "@user commented on a thread you participated in.", + ExpectedMessage: "user commented on a thread you participated in.", }, "generic message with channel, group message channel, no mention": { Message: "this is a message", PushNotificationContents: model.GENERIC_NOTIFICATION, ChannelType: model.CHANNEL_GROUP, - ExpectedMessage: "@user posted a message.", + ExpectedMessage: "user posted a message.", }, "generic message with channel, group message channel, mention": { Message: "this is a message", explicitMention: true, PushNotificationContents: model.GENERIC_NOTIFICATION, ChannelType: model.CHANNEL_GROUP, - ExpectedMessage: "@user mentioned you.", + ExpectedMessage: "user mentioned you.", }, "generic message with channel, group message channel, channel wide mention": { Message: "this is a message", channelWideMention: true, PushNotificationContents: model.GENERIC_NOTIFICATION, ChannelType: model.CHANNEL_GROUP, - ExpectedMessage: "@user notified the channel.", + ExpectedMessage: "user notified the channel.", }, "generic message, group message channel, commented on post": { Message: "this is a message", replyToThreadType: THREAD_ROOT, PushNotificationContents: model.GENERIC_NOTIFICATION, ChannelType: model.CHANNEL_GROUP, - ExpectedMessage: "@user commented on your post.", + ExpectedMessage: "user commented on your post.", }, "generic message, group message channel, commented on thread": { Message: "this is a message", replyToThreadType: THREAD_ANY, PushNotificationContents: model.GENERIC_NOTIFICATION, ChannelType: model.CHANNEL_GROUP, - ExpectedMessage: "@user commented on a thread you participated in.", + ExpectedMessage: "user commented on a thread you participated in.", }, "generic message with channel, direct message channel, no mention": { Message: "this is a message", @@ -790,40 +790,40 @@ func TestGetPushNotificationMessage(t *testing.T) { Message: "this is a message", PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, ChannelType: model.CHANNEL_OPEN, - ExpectedMessage: "@user posted a message.", + ExpectedMessage: "user posted a message.", }, "generic message without channel, public channel, mention": { Message: "this is a message", explicitMention: true, PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, ChannelType: model.CHANNEL_OPEN, - ExpectedMessage: "@user mentioned you.", + ExpectedMessage: "user mentioned you.", }, "generic message without channel, private channel, no mention": { Message: "this is a message", PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, ChannelType: model.CHANNEL_PRIVATE, - ExpectedMessage: "@user posted a message.", + ExpectedMessage: "user posted a message.", }, "generic message without channel, private channel, mention": { Message: "this is a message", explicitMention: true, PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, ChannelType: model.CHANNEL_PRIVATE, - ExpectedMessage: "@user mentioned you.", + ExpectedMessage: "user mentioned you.", }, "generic message without channel, group message channel, no mention": { Message: "this is a message", PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, ChannelType: model.CHANNEL_GROUP, - ExpectedMessage: "@user posted a message.", + ExpectedMessage: "user posted a message.", }, "generic message without channel, group message channel, mention": { Message: "this is a message", explicitMention: true, PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, ChannelType: model.CHANNEL_GROUP, - ExpectedMessage: "@user mentioned you.", + ExpectedMessage: "user mentioned you.", }, "generic message without channel, direct message channel, no mention": { Message: "this is a message", @@ -841,17 +841,17 @@ func TestGetPushNotificationMessage(t *testing.T) { "only files, public channel": { HasFiles: true, ChannelType: model.CHANNEL_OPEN, - ExpectedMessage: "@user attached a file.", + ExpectedMessage: "user attached a file.", }, "only files, private channel": { HasFiles: true, ChannelType: model.CHANNEL_PRIVATE, - ExpectedMessage: "@user attached a file.", + ExpectedMessage: "user attached a file.", }, "only files, group message channel": { HasFiles: true, ChannelType: model.CHANNEL_GROUP, - ExpectedMessage: "@user attached a file.", + ExpectedMessage: "user attached a file.", }, "only files, direct message channel": { HasFiles: true, @@ -862,7 +862,7 @@ func TestGetPushNotificationMessage(t *testing.T) { HasFiles: true, PushNotificationContents: model.GENERIC_NO_CHANNEL_NOTIFICATION, ChannelType: model.CHANNEL_OPEN, - ExpectedMessage: "@user attached a file.", + ExpectedMessage: "user attached a file.", }, } { t.Run(name, func(t *testing.T) {