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
This commit is contained in:
Sheshagiri Rao Mallipedhi
2019-04-23 21:50:19 +05:30
committed by Elias Nahum
parent be4b473aee
commit 446c6d452e
2 changed files with 49 additions and 45 deletions

View File

@@ -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) {

View File

@@ -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) {