From ce8c2d34d7ecafacb03ce66ff08bc0f7312f6632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 1 Feb 2016 10:14:30 +0100 Subject: [PATCH] FIX: add a 20 seconds grace period before sending a notification about a PM --- app/models/user_email_observer.rb | 13 ++++++++----- spec/models/user_email_observer_spec.rb | 6 +++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/models/user_email_observer.rb b/app/models/user_email_observer.rb index 8143fef4f64..889f9cdd947 100644 --- a/app/models/user_email_observer.rb +++ b/app/models/user_email_observer.rb @@ -29,15 +29,15 @@ class UserEmailObserver < ActiveRecord::Observer end def private_message - enqueue_private(:user_private_message, 0) + enqueue_private(:user_private_message) end def invited_to_private_message - enqueue(:user_invited_to_private_message, 0) + enqueue(:user_invited_to_private_message, private_delay) end def invited_to_topic - enqueue(:user_invited_to_topic, 0) + enqueue(:user_invited_to_topic, private_delay) end def self.notification_params(notification, type) @@ -64,7 +64,7 @@ class UserEmailObserver < ActiveRecord::Observer perform_enqueue(type,delay) end - def enqueue_private(type, delay=default_delay) + def enqueue_private(type, delay=private_delay) return unless notification.user.email_private_messages? perform_enqueue(type,delay) end @@ -76,11 +76,14 @@ class UserEmailObserver < ActiveRecord::Observer Jobs.enqueue_in(delay, :user_email, self.class.notification_params(notification, type)) end - def default_delay SiteSetting.email_time_window_mins.minutes end + def private_delay + 20.seconds + end + end def after_commit(notification) diff --git a/spec/models/user_email_observer_spec.rb b/spec/models/user_email_observer_spec.rb index 0824f1949e3..9e91271d524 100644 --- a/spec/models/user_email_observer_spec.rb +++ b/spec/models/user_email_observer_spec.rb @@ -109,7 +109,7 @@ describe UserEmailObserver do context 'user_private_message' do let(:type) { :user_private_message } - let(:delay) { 0 } + let(:delay) { 20.seconds } let!(:notification) { create_notification(6) } include_examples "enqueue_private" @@ -117,7 +117,7 @@ describe UserEmailObserver do context 'user_invited_to_private_message' do let(:type) { :user_invited_to_private_message } - let(:delay) { 0 } + let(:delay) { 20.seconds } let!(:notification) { create_notification(7) } include_examples "enqueue_public" @@ -125,7 +125,7 @@ describe UserEmailObserver do context 'user_invited_to_topic' do let(:type) { :user_invited_to_topic } - let(:delay) { 0 } + let(:delay) { 20.seconds } let!(:notification) { create_notification(13) } include_examples "enqueue_public"