summaryrefslogtreecommitdiffstats
path: root/app/notification_push.go
diff options
context:
space:
mode:
authorHarrison Healey <harrisonmhealey@gmail.com>2018-09-17 14:50:12 -0400
committerSudheer <sudheer.105@gmail.com>2018-09-18 00:20:12 +0530
commit6c2a5555b85bd15106df5f4f631bb6e945a187b8 (patch)
treed1267e537a741171a50ddec4ff08e11e9e5dbd26 /app/notification_push.go
parentab99f0656fabed8a62a8c6340be7d538cc7bf8d9 (diff)
downloadchat-6c2a5555b85bd15106df5f4f631bb6e945a187b8.tar.gz
chat-6c2a5555b85bd15106df5f4f631bb6e945a187b8.tar.bz2
chat-6c2a5555b85bd15106df5f4f631bb6e945a187b8.zip
MM-11700 Clean up handling of user display names for notifications (#9343)
* MM-11700 Clean up handling of user display names for notifications
Diffstat (limited to 'app/notification_push.go')
-rw-r--r--app/notification_push.go34
1 files changed, 16 insertions, 18 deletions
diff --git a/app/notification_push.go b/app/notification_push.go
index 517988a97..5c7df0da7 100644
--- a/app/notification_push.go
+++ b/app/notification_push.go
@@ -15,13 +15,23 @@ import (
"github.com/nicksnyder/go-i18n/i18n"
)
-func (a *App) sendPushNotification(post *model.Post, user *model.User, channel *model.Channel, channelName string, sender *model.User, senderName string,
- explicitMention, channelWideMention bool, replyToThreadType string) *model.AppError {
+func (a *App) sendPushNotification(notification *postNotification, user *model.User, explicitMention, channelWideMention bool, replyToThreadType string) *model.AppError {
+ channel := notification.channel
+ post := notification.post
+
cfg := a.Config()
- contentsConfig := *cfg.EmailSettings.PushNotificationContents
- teammateNameConfig := *cfg.TeamSettings.TeammateNameDisplay
+
+ var nameFormat string
+ if result := <-a.Srv.Store.Preference().Get(user.Id, model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS, model.PREFERENCE_NAME_NAME_FORMAT); result.Err != nil {
+ nameFormat = *a.Config().TeamSettings.TeammateNameDisplay
+ } else {
+ nameFormat = result.Data.(model.Preference).Value
+ }
+
+ channelName := notification.GetChannelName(nameFormat, user.Id)
+ senderName := notification.GetSenderName(nameFormat, cfg.ServiceSettings.EnablePostUsernameOverride)
+
sessions, err := a.getMobileAppSessions(user.Id)
- sentBySystem := senderName == utils.T("system.message.name")
if err != nil {
return err
}
@@ -43,25 +53,13 @@ func (a *App) sendPushNotification(post *model.Post, user *model.User, channel *
msg.RootId = post.RootId
msg.SenderId = post.UserId
- if !sentBySystem {
- senderName = sender.GetDisplayName(teammateNameConfig)
- preference, prefError := a.GetPreferenceByCategoryAndNameForUser(user.Id, model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS, "name_format")
- if prefError == nil && preference.Value != teammateNameConfig {
- senderName = sender.GetDisplayName(preference.Value)
- }
- }
-
- if channel.Type == model.CHANNEL_DIRECT {
- channelName = fmt.Sprintf("@%v", senderName)
- }
-
+ contentsConfig := *cfg.EmailSettings.PushNotificationContents
if contentsConfig != model.GENERIC_NO_CHANNEL_NOTIFICATION || channel.Type == model.CHANNEL_DIRECT {
msg.ChannelName = channelName
}
if ou, ok := post.Props["override_username"].(string); ok && cfg.ServiceSettings.EnablePostUsernameOverride {
msg.OverrideUsername = ou
- senderName = ou
}
if oi, ok := post.Props["override_icon_url"].(string); ok && cfg.ServiceSettings.EnablePostIconOverride {