summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarrison Healey <harrisonmhealey@gmail.com>2016-09-06 17:51:42 -0400
committerenahum <nahumhbl@gmail.com>2016-09-06 18:51:42 -0300
commit73692f010e1a0bf62f0a502797aca94f99012385 (patch)
treecee41dd48ec51c904bf29ad81c1d5a4a2dddb009
parent024a72b440345709692d46f2b15d5cb958926359 (diff)
downloadchat-73692f010e1a0bf62f0a502797aca94f99012385.tar.gz
chat-73692f010e1a0bf62f0a502797aca94f99012385.tar.bz2
chat-73692f010e1a0bf62f0a502797aca94f99012385.zip
PLT-3775/PLT-4067 Fixes for email notifications for 3.4
-rw-r--r--api/post.go39
-rw-r--r--i18n/en.json4
-rw-r--r--webapp/components/user_settings/email_notification_setting.jsx6
-rw-r--r--webapp/i18n/en.json1
4 files changed, 48 insertions, 2 deletions
diff --git a/api/post.go b/api/post.go
index d62b85059..f581b1bf4 100644
--- a/api/post.go
+++ b/api/post.go
@@ -794,9 +794,44 @@ func sendNotificationEmail(c *Context, post *model.Post, user *model.User, chann
return
}
- if *utils.Cfg.EmailSettings.EnableEmailBatching {
- if err := AddNotificationEmailToBatch(user, post, team); err == nil {
+ if channel.Type == model.CHANNEL_DIRECT && channel.TeamId != team.Id {
+ // this message is a cross-team DM so it we need to find a team that the recipient is on to use in the link
+ if result := <-Srv.Store.Team().GetTeamsByUserId(user.Id); result.Err != nil {
+ l4g.Error(utils.T("api.post.send_notifications_and_forget.get_teams.error"), user.Id, result.Err)
return
+ } else {
+ // if the recipient isn't in the current user's team, just pick one
+ teams := result.Data.([]*model.Team)
+ found := false
+
+ for i := range teams {
+ if teams[i].Id == team.Id {
+ found = true
+ break
+ }
+ }
+
+ if !found {
+ team = teams[0]
+ }
+ }
+ }
+
+ if *utils.Cfg.EmailSettings.EnableEmailBatching {
+ var sendBatched bool
+
+ if result := <-Srv.Store.Preference().Get(user.Id, model.PREFERENCE_CATEGORY_NOTIFICATIONS, model.PREFERENCE_NAME_EMAIL_INTERVAL); result.Err != nil {
+ // if the call fails, assume it hasn't been set and use the default
+ sendBatched = false
+ } else {
+ // default to not using batching if the setting is set to immediate
+ sendBatched = result.Data.(model.Preference).Value != model.PREFERENCE_DEFAULT_EMAIL_INTERVAL
+ }
+
+ if sendBatched {
+ if err := AddNotificationEmailToBatch(user, post, team); err == nil {
+ return
+ }
}
// fall back to sending a single email if we can't batch it for some reason
diff --git a/i18n/en.json b/i18n/en.json
index ad2992902..af0500f3e 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -1272,6 +1272,10 @@
"translation": "Failed to retrieve comment thread posts in notifications root_post_id=%v, err=%v"
},
{
+ "id": "api.post.send_notifications_and_forget.get_teams.error",
+ "translation": "Failed to get teams when sending cross-team DM user_id=%v, err=%v"
+ },
+ {
"id": "api.post.send_notifications_and_forget.mention_body",
"translation": "You have one new mention."
},
diff --git a/webapp/components/user_settings/email_notification_setting.jsx b/webapp/components/user_settings/email_notification_setting.jsx
index c45872a82..e10fd5154 100644
--- a/webapp/components/user_settings/email_notification_setting.jsx
+++ b/webapp/components/user_settings/email_notification_setting.jsx
@@ -159,6 +159,12 @@ export default class EmailNotificationSetting extends React.Component {
title={localizeMessage('user.settings.notifications.emailNotifications', 'Email notifications')}
inputs={[
<div key='userNotificationEmailOptions'>
+ <label>
+ <FormattedMessage
+ id='user.settings.notifications.email.send'
+ defaultMessage='Send email notifications'
+ />
+ </label>
<div className='radio'>
<label>
<input
diff --git a/webapp/i18n/en.json b/webapp/i18n/en.json
index 6cb66bd58..78496eb77 100644
--- a/webapp/i18n/en.json
+++ b/webapp/i18n/en.json
@@ -1899,6 +1899,7 @@
"user.settings.notifications.email.everyXMinutes": "Every {count, plural, one {minute} other {{count, number} minutes}}",
"user.settings.notifications.email.immediately": "Immediately",
"user.settings.notifications.email.never": "Never",
+ "user.settings.notifications.email.send": "Send email notifications",
"user.settings.notifications.emailBatchingInfo": "Notifications received over the time period selected are combined and sent in a single email.",
"user.settings.notifications.emailInfo": "Email notifications are sent for mentions and direct messages when you are offline or away from {siteName} for more than 5 minutes.",
"user.settings.notifications.emailNotifications": "Email notifications",