summaryrefslogtreecommitdiffstats
path: root/app/email_batching.go
diff options
context:
space:
mode:
authorJonathan <jonfritz@gmail.com>2017-08-05 19:52:35 -0400
committerSaturnino Abril <saturnino.abril@gmail.com>2017-08-06 07:52:35 +0800
commit178ccd16cba26144eac404f413440867b360033c (patch)
tree5a2304ee8fbe7586d4101b7e38cd85756e114a05 /app/email_batching.go
parent9f3713aa98011596a62315fd3b96fa2e77044081 (diff)
downloadchat-178ccd16cba26144eac404f413440867b360033c.tar.gz
chat-178ccd16cba26144eac404f413440867b360033c.tar.bz2
chat-178ccd16cba26144eac404f413440867b360033c.zip
System Console: Email notification content setting (#7122)
* PLT-7195: Added new config option, new license feature, and config UI to system console. Still need to implement behaviour change in email batching code * PLT-7195: Modified batch emails to respect email notification content type setting * PLT-7195: Tweaking the colours a bit * PLT-7195: Added support for email notification content type setting in immediate (non-batched) notification messages. Attempted to clean up the code somewhat. Unit tests coming in a future commit * PLT-7195: Added unit tests for non-batched emails * Checked license when applying email content settings * Changed return type of getFormattedPostTime
Diffstat (limited to 'app/email_batching.go')
-rw-r--r--app/email_batching.go62
1 files changed, 42 insertions, 20 deletions
diff --git a/app/email_batching.go b/app/email_batching.go
index e69870814..a578daf04 100644
--- a/app/email_batching.go
+++ b/app/email_batching.go
@@ -177,9 +177,30 @@ func sendBatchedEmailNotification(userId string, notifications []*batchedNotific
var contents string
for _, notification := range notifications {
- template := utils.NewHTMLTemplate("post_batched_post", user.Locale)
+ var sender *model.User
+ schan := Srv.Store.User().Get(notification.post.UserId)
+ if result := <-schan; result.Err != nil {
+ l4g.Warn(utils.T("api.email_batching.render_batched_post.sender.app_error"))
+ continue
+ } else {
+ sender = result.Data.(*model.User)
+ }
- contents += renderBatchedPost(template, notification.post, notification.teamName, displayNameFormat, translateFunc)
+ var channel *model.Channel
+ cchan := Srv.Store.Channel().Get(notification.post.ChannelId, true)
+ if result := <-cchan; result.Err != nil {
+ l4g.Warn(utils.T("api.email_batching.render_batched_post.channel.app_error"))
+ continue
+ } else {
+ channel = result.Data.(*model.Channel)
+ }
+
+ emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
+ if utils.IsLicensed && *utils.License.Features.EmailNotificationContents {
+ emailNotificationContentsType = *utils.Cfg.EmailSettings.EmailNotificationContentsType
+ }
+
+ contents += renderBatchedPost(notification, channel, sender, *utils.Cfg.ServiceSettings.SiteURL, displayNameFormat, translateFunc, user.Locale, emailNotificationContentsType)
}
tm := time.Unix(notifications[0].post.CreateAt/1000, 0)
@@ -201,15 +222,21 @@ func sendBatchedEmailNotification(userId string, notifications []*batchedNotific
}
}
-func renderBatchedPost(template *utils.HTMLTemplate, post *model.Post, teamName string, displayNameFormat string, translateFunc i18n.TranslateFunc) string {
- schan := Srv.Store.User().Get(post.UserId)
- cchan := Srv.Store.Channel().Get(post.ChannelId, true)
+func renderBatchedPost(notification *batchedNotification, channel *model.Channel, sender *model.User, siteURL string, displayNameFormat string, translateFunc i18n.TranslateFunc, userLocale string, emailNotificationContentsType string) string {
+ // don't include message contents if email notification contents type is set to generic
+ var template *utils.HTMLTemplate
+ if emailNotificationContentsType == model.EMAIL_NOTIFICATION_CONTENTS_FULL {
+ template = utils.NewHTMLTemplate("post_batched_post_full", userLocale)
+ } else {
+ template = utils.NewHTMLTemplate("post_batched_post_generic", userLocale)
+ }
template.Props["Button"] = translateFunc("api.email_batching.render_batched_post.go_to_post")
- template.Props["PostMessage"] = GetMessageForNotification(post, translateFunc)
- template.Props["PostLink"] = *utils.Cfg.ServiceSettings.SiteURL + "/" + teamName + "/pl/" + post.Id
+ template.Props["PostMessage"] = GetMessageForNotification(notification.post, translateFunc)
+ template.Props["PostLink"] = siteURL + "/" + notification.teamName + "/pl/" + notification.post.Id
+ template.Props["SenderName"] = sender.GetDisplayName(displayNameFormat)
- tm := time.Unix(post.CreateAt/1000, 0)
+ tm := time.Unix(notification.post.CreateAt/1000, 0)
timezone, _ := tm.Zone()
template.Props["Date"] = translateFunc("api.email_batching.render_batched_post.date", map[string]interface{}{
@@ -221,22 +248,17 @@ func renderBatchedPost(template *utils.HTMLTemplate, post *model.Post, teamName
"Timezone": timezone,
})
- if result := <-schan; result.Err != nil {
- l4g.Warn(utils.T("api.email_batching.render_batched_post.sender.app_error"))
- return ""
- } else {
- template.Props["SenderName"] = result.Data.(*model.User).GetDisplayName(displayNameFormat)
- }
-
- if result := <-cchan; result.Err != nil {
- l4g.Warn(utils.T("api.email_batching.render_batched_post.channel.app_error"))
- return ""
- } else if channel := result.Data.(*model.Channel); channel.Type == model.CHANNEL_DIRECT {
+ if channel.Type == model.CHANNEL_DIRECT {
template.Props["ChannelName"] = translateFunc("api.email_batching.render_batched_post.direct_message")
} else if channel.Type == model.CHANNEL_GROUP {
template.Props["ChannelName"] = translateFunc("api.email_batching.render_batched_post.group_message")
} else {
- template.Props["ChannelName"] = channel.DisplayName
+ // don't include channel name if email notification contents type is set to generic
+ if emailNotificationContentsType == model.EMAIL_NOTIFICATION_CONTENTS_FULL {
+ template.Props["ChannelName"] = channel.DisplayName
+ } else {
+ template.Props["ChannelName"] = translateFunc("api.email_batching.render_batched_post.notification")
+ }
}
return template.Render()