From 02f8c18f40cd0e973e4c75b751e8fcbbbd019728 Mon Sep 17 00:00:00 2001 From: Ugurcan Turkdogan Date: Tue, 15 May 2018 13:43:59 -0700 Subject: Update email notification subject line and contents for Group Messages (#8689) Reordered notification strings MM-10335 Changed uppercase CHANNEL to Lowercase Channel, added @ sign before username on notifications Added @ sign in front of username in all email notifications. Capitalized Direct Message and Group Message in email notifications. Fixed the issue with long group message names. Removed executable bit --- app/notification.go | 77 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 64 insertions(+), 13 deletions(-) (limited to 'app/notification.go') diff --git a/app/notification.go b/app/notification.go index 4bdc6c94f..0fbc33060 100644 --- a/app/notification.go +++ b/app/notification.go @@ -217,7 +217,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod } if userAllowsEmails && status.Status != model.STATUS_ONLINE && profileMap[id].DeleteAt == 0 { - a.sendNotificationEmail(post, profileMap[id], channel, team, senderName, sender) + a.sendNotificationEmail(post, profileMap[id], channel, team, channelName, senderName, sender) } } } @@ -351,7 +351,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod return mentionedUsersList, nil } -func (a *App) sendNotificationEmail(post *model.Post, user *model.User, channel *model.Channel, team *model.Team, senderName string, sender *model.User) *model.AppError { +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 { if channel.IsGroupOrDirect() { if result := <-a.Srv.Store.Team().GetTeamsByUserId(user.Id); result.Err != nil { return result.Err @@ -396,22 +396,24 @@ func (a *App) sendNotificationEmail(post *model.Post, user *model.User, channel translateFunc := utils.GetUserTranslations(user.Locale) + emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL + if license := a.License(); license != nil && *license.Features.EmailNotificationContents { + emailNotificationContentsType = *a.Config().EmailSettings.EmailNotificationContentsType + } + var subjectText string if channel.Type == model.CHANNEL_DIRECT { subjectText = getDirectMessageNotificationEmailSubject(post, translateFunc, a.Config().TeamSettings.SiteName, senderName) + } else if channel.Type == model.CHANNEL_GROUP { + subjectText = getGroupMessageNotificationEmailSubject(post, translateFunc, a.Config().TeamSettings.SiteName, channelName, emailNotificationContentsType) } else if *a.Config().EmailSettings.UseChannelInEmailNotifications { subjectText = getNotificationEmailSubject(post, translateFunc, a.Config().TeamSettings.SiteName, team.DisplayName+" ("+channel.DisplayName+")") } else { subjectText = getNotificationEmailSubject(post, translateFunc, a.Config().TeamSettings.SiteName, team.DisplayName) } - emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL - if license := a.License(); license != nil && *license.Features.EmailNotificationContents { - emailNotificationContentsType = *a.Config().EmailSettings.EmailNotificationContentsType - } - teamURL := a.GetSiteURL() + "/" + team.Name - var bodyText = a.getNotificationEmailBody(user, post, channel, senderName, team.Name, teamURL, emailNotificationContentsType, translateFunc) + var bodyText = a.getNotificationEmailBody(user, post, channel, channelName, senderName, team.Name, teamURL, emailNotificationContentsType, translateFunc) a.Go(func() { if err := a.SendMail(user.Email, html.UnescapeString(subjectText), bodyText); err != nil { @@ -456,10 +458,37 @@ func getNotificationEmailSubject(post *model.Post, translateFunc i18n.TranslateF return translateFunc("app.notification.subject.notification.full", subjectParameters) } +/** + * Computes the subject line for group email messages + */ +func getGroupMessageNotificationEmailSubject(post *model.Post, translateFunc i18n.TranslateFunc, siteName string, channelName string, emailNotificationContentsType string) string { + t := getFormattedPostTime(post, translateFunc) + var subjectText string + if emailNotificationContentsType == model.EMAIL_NOTIFICATION_CONTENTS_FULL { + var subjectParameters = map[string]interface{}{ + "SiteName": siteName, + "ChannelName": channelName, + "Month": t.Month, + "Day": t.Day, + "Year": t.Year, + } + subjectText = translateFunc("app.notification.subject.group_message.full", subjectParameters) + } else { + var subjectParameters = map[string]interface{}{ + "SiteName": siteName, + "Month": t.Month, + "Day": t.Day, + "Year": t.Year, + } + subjectText = translateFunc("app.notification.subject.group_message.generic", subjectParameters) + } + return subjectText +} + /** * Computes the email body for notification messages */ -func (a *App) getNotificationEmailBody(recipient *model.User, post *model.Post, channel *model.Channel, senderName string, teamName string, teamURL string, emailNotificationContentsType string, translateFunc i18n.TranslateFunc) string { +func (a *App) getNotificationEmailBody(recipient *model.User, post *model.Post, channel *model.Channel, channelName string, senderName string, teamName string, teamURL string, emailNotificationContentsType string, translateFunc i18n.TranslateFunc) string { // only include message contents in notification email if email notification contents type is set to full var bodyPage *utils.HTMLTemplate if emailNotificationContentsType == model.EMAIL_NOTIFICATION_CONTENTS_FULL { @@ -476,10 +505,6 @@ func (a *App) getNotificationEmailBody(recipient *model.User, post *model.Post, bodyPage.Props["TeamLink"] = teamURL } - var channelName = channel.DisplayName - if channel.Type == model.CHANNEL_GROUP { - channelName = translateFunc("api.templates.channel_name.group") - } t := getFormattedPostTime(post, translateFunc) var bodyText string @@ -509,6 +534,32 @@ func (a *App) getNotificationEmailBody(recipient *model.User, post *model.Post, "Day": t.Day, }) } + } else if channel.Type == model.CHANNEL_GROUP { + if emailNotificationContentsType == model.EMAIL_NOTIFICATION_CONTENTS_FULL { + bodyText = translateFunc("app.notification.body.intro.group_message.full") + info = utils.TranslateAsHtml(translateFunc, "app.notification.body.text.group_message.full", + map[string]interface{}{ + "ChannelName": channelName, + "SenderName": senderName, + "Hour": t.Hour, + "Minute": t.Minute, + "TimeZone": t.TimeZone, + "Month": t.Month, + "Day": t.Day, + }) + } else { + bodyText = translateFunc("app.notification.body.intro.group_message.generic", map[string]interface{}{ + "SenderName": senderName, + }) + info = utils.TranslateAsHtml(translateFunc, "app.notification.body.text.group_message.generic", + map[string]interface{}{ + "Hour": t.Hour, + "Minute": t.Minute, + "TimeZone": t.TimeZone, + "Month": t.Month, + "Day": t.Day, + }) + } } else { if emailNotificationContentsType == model.EMAIL_NOTIFICATION_CONTENTS_FULL { bodyText = translateFunc("app.notification.body.intro.notification.full") -- cgit v1.2.3-1-g7c22