summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJonathan <jonfritz@gmail.com>2017-07-31 11:51:43 -0400
committerHarrison Healey <harrisonmhealey@gmail.com>2017-07-31 11:51:43 -0400
commitd01261a228fd6cda693623a85832bd567693512e (patch)
tree473326274476f3ae54382e59403fd8b5e9c832f1 /app
parent8d7dcf44e2c6951a501c74dca21d453f2f9966e4 (diff)
downloadchat-d01261a228fd6cda693623a85832bd567693512e.tar.gz
chat-d01261a228fd6cda693623a85832bd567693512e.tar.bz2
chat-d01261a228fd6cda693623a85832bd567693512e.zip
PLT-7177: Change the default email frequency to 15 minutes if batching is enabled on the server. (#7036)
* PLT-7177: Found default preference that needs to be changed * PLT-7177: Front end behaves as desired * PLT-7177: Changed default batching interval on server side * PLT-7177: Added unit tests for new default interval * PLT-7177: Removed unused import * PLT-7177: Renamed constants to increase clarity
Diffstat (limited to 'app')
-rw-r--r--app/email_batching.go7
-rw-r--r--app/email_batching_test.go80
-rw-r--r--app/notification.go7
3 files changed, 87 insertions, 7 deletions
diff --git a/app/email_batching.go b/app/email_batching.go
index 5e4a36daf..e69870814 100644
--- a/app/email_batching.go
+++ b/app/email_batching.go
@@ -140,13 +140,14 @@ func (job *EmailBatchingJob) checkPendingNotifications(now time.Time, handler fu
// get how long we need to wait to send notifications to the user
var interval int64
if result := <-pchan; result.Err != nil {
- // default to 30 seconds to match the send "immediate" setting
- interval, _ = strconv.ParseInt(model.PREFERENCE_DEFAULT_EMAIL_INTERVAL, 10, 64)
+ // use the default batching interval if an error ocurrs while fetching user preferences
+ interval, _ = strconv.ParseInt(model.PREFERENCE_EMAIL_INTERVAL_BATCHING_SECONDS, 10, 64)
} else {
preference := result.Data.(model.Preference)
if value, err := strconv.ParseInt(preference.Value, 10, 64); err != nil {
- interval, _ = strconv.ParseInt(model.PREFERENCE_DEFAULT_EMAIL_INTERVAL, 10, 64)
+ // // use the default batching interval if an error ocurrs while deserializing user preferences
+ interval, _ = strconv.ParseInt(model.PREFERENCE_EMAIL_INTERVAL_BATCHING_SECONDS, 10, 64)
} else {
interval = value
}
diff --git a/app/email_batching_test.go b/app/email_batching_test.go
index 74fbea5c3..b5c18d378 100644
--- a/app/email_batching_test.go
+++ b/app/email_batching_test.go
@@ -191,3 +191,83 @@ func TestCheckPendingNotifications(t *testing.T) {
t.Fatal("timed out waiting for second post notification")
}
}
+
+/**
+ * Ensures that email batch interval defaults to 15 minutes for users that haven't explicitly set this preference
+ */
+func TestCheckPendingNotificationsDefaultInterval(t *testing.T) {
+ Setup()
+ id1 := model.NewId()
+ job := MakeEmailBatchingJob(128)
+
+ // bypasses recent user activity check
+ store.Must(Srv.Store.Status().SaveOrUpdate(&model.Status{
+ UserId: id1,
+ LastActivityAt: 9999000,
+ }))
+
+ job.pendingNotifications[id1] = []*batchedNotification{
+ {
+ post: &model.Post{
+ UserId: id1,
+ CreateAt: 10000000,
+ },
+ },
+ }
+
+ // notifications should not be sent 1s after post was created, because default batch interval is 15mins
+ job.checkPendingNotifications(time.Unix(10001, 0), func(string, []*batchedNotification) {})
+ if job.pendingNotifications[id1] == nil || len(job.pendingNotifications[id1]) != 1 {
+ t.Fatal("shouldn't have sent queued post")
+ }
+
+ // notifications should be sent 901s after post was created, because default batch interval is 15mins
+ job.checkPendingNotifications(time.Unix(10901, 0), func(string, []*batchedNotification) {})
+ if job.pendingNotifications[id1] != nil || len(job.pendingNotifications[id1]) != 0 {
+ t.Fatal("should have sent queued post")
+ }
+}
+
+/**
+ * Ensures that email batch interval defaults to 15 minutes if user preference is invalid
+ */
+func TestCheckPendingNotificationsCantParseInterval(t *testing.T) {
+ Setup()
+ id1 := model.NewId()
+ job := MakeEmailBatchingJob(128)
+
+ // bypasses recent user activity check
+ store.Must(Srv.Store.Status().SaveOrUpdate(&model.Status{
+ UserId: id1,
+ LastActivityAt: 9999000,
+ }))
+
+ // preference value is not an integer, so we'll fall back to the default 15min value
+ store.Must(Srv.Store.Preference().Save(&model.Preferences{{
+ UserId: id1,
+ Category: model.PREFERENCE_CATEGORY_NOTIFICATIONS,
+ Name: model.PREFERENCE_NAME_EMAIL_INTERVAL,
+ Value: "notAnIntegerValue",
+ }}))
+
+ job.pendingNotifications[id1] = []*batchedNotification{
+ {
+ post: &model.Post{
+ UserId: id1,
+ CreateAt: 10000000,
+ },
+ },
+ }
+
+ // notifications should not be sent 1s after post was created, because default batch interval is 15mins
+ job.checkPendingNotifications(time.Unix(10001, 0), func(string, []*batchedNotification) {})
+ if job.pendingNotifications[id1] == nil || len(job.pendingNotifications[id1]) != 1 {
+ t.Fatal("shouldn't have sent queued post")
+ }
+
+ // notifications should be sent 901s after post was created, because default batch interval is 15mins
+ job.checkPendingNotifications(time.Unix(10901, 0), func(string, []*batchedNotification) {})
+ if job.pendingNotifications[id1] != nil || len(job.pendingNotifications[id1]) != 0 {
+ t.Fatal("should have sent queued post")
+ }
+}
diff --git a/app/notification.go b/app/notification.go
index d2eb44b3a..d145b21b3 100644
--- a/app/notification.go
+++ b/app/notification.go
@@ -332,13 +332,12 @@ func sendNotificationEmail(post *model.Post, user *model.User, channel *model.Ch
}
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
+ // if the call fails, assume it hasn't been set and don't batch notifications for this user
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 the user has chosen to receive notifications immediately, don't batch them
+ sendBatched = result.Data.(model.Preference).Value != model.PREFERENCE_EMAIL_INTERVAL_NO_BATCHING_SECONDS
}
if sendBatched {