From 6c2a5555b85bd15106df5f4f631bb6e945a187b8 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Mon, 17 Sep 2018 14:50:12 -0400 Subject: MM-11700 Clean up handling of user display names for notifications (#9343) * MM-11700 Clean up handling of user display names for notifications --- app/notification_email.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'app/notification_email.go') diff --git a/app/notification_email.go b/app/notification_email.go index b3835a4ee..cfc1bb4fd 100644 --- a/app/notification_email.go +++ b/app/notification_email.go @@ -17,7 +17,10 @@ import ( "github.com/nicksnyder/go-i18n/i18n" ) -func (a *App) sendNotificationEmail(post *model.Post, user *model.User, channel *model.Channel, team *model.Team, channelName string, senderName string, sender *model.User) *model.AppError { +func (a *App) sendNotificationEmail(notification *postNotification, user *model.User, team *model.Team) *model.AppError { + channel := notification.channel + post := notification.post + if channel.IsGroupOrDirect() { if result := <-a.Srv.Store.Team().GetTeamsByUserId(user.Id); result.Err != nil { return result.Err @@ -41,6 +44,7 @@ func (a *App) sendNotificationEmail(post *model.Post, user *model.User, channel } } } + if *a.Config().EmailSettings.EnableEmailBatching { var sendBatched bool if result := <-a.Srv.Store.Preference().Get(user.Id, model.PREFERENCE_CATEGORY_NOTIFICATIONS, model.PREFERENCE_NAME_EMAIL_INTERVAL); result.Err != nil { @@ -60,14 +64,25 @@ func (a *App) sendNotificationEmail(post *model.Post, user *model.User, channel // fall back to sending a single email if we can't batch it for some reason } - var useMilitaryTime bool translateFunc := utils.GetUserTranslations(user.Locale) - if result := <-a.Srv.Store.Preference().Get(user.Id, model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS, "use_military_time"); result.Err != nil { + + var useMilitaryTime bool + if result := <-a.Srv.Store.Preference().Get(user.Id, model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS, model.PREFERENCE_NAME_USE_MILITARY_TIME); result.Err != nil { useMilitaryTime = true } else { useMilitaryTime = result.Data.(model.Preference).Value == "true" } + 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, "") + senderName := notification.GetSenderName(nameFormat, a.Config().ServiceSettings.EnablePostUsernameOverride) + emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL if license := a.License(); license != nil && *license.Features.EmailNotificationContents { emailNotificationContentsType = *a.Config().EmailSettings.EmailNotificationContentsType @@ -79,7 +94,7 @@ func (a *App) sendNotificationEmail(post *model.Post, user *model.User, channel } else if channel.Type == model.CHANNEL_GROUP { subjectText = getGroupMessageNotificationEmailSubject(user, post, translateFunc, a.Config().TeamSettings.SiteName, channelName, emailNotificationContentsType, useMilitaryTime) } else if *a.Config().EmailSettings.UseChannelInEmailNotifications { - subjectText = getNotificationEmailSubject(user, post, translateFunc, a.Config().TeamSettings.SiteName, team.DisplayName+" ("+channel.DisplayName+")", useMilitaryTime) + subjectText = getNotificationEmailSubject(user, post, translateFunc, a.Config().TeamSettings.SiteName, team.DisplayName+" ("+channelName+")", useMilitaryTime) } else { subjectText = getNotificationEmailSubject(user, post, translateFunc, a.Config().TeamSettings.SiteName, team.DisplayName, useMilitaryTime) } -- cgit v1.2.3-1-g7c22