A platform for community discussion. Free, open, simple.
FIX: when unread reply notification exists don't create new (#8921)
Krzysztof Kotlareke90f9e5cc479
diff --git a/app/services/post_alerter.rb b/app/services/post_alerter.rbindex 7a4580ad189..ea1b8105903 100644--- a/app/services/post_alerter.rb+++ b/app/services/post_alerter.rb@@ -261,6 +261,7 @@ class PostAlerterenddef should_notify_previous?(user, post, notification, opts)+ return false unless notificationcase notification.notification_typewhen Notification.types[:edited] then should_notify_edit?(notification, post, opts)when Notification.types[:liked] then should_notify_like?(user, notification)@@ -330,7 +331,7 @@ class PostAlerter# Don't notify the same user about the same type of notification on the same postexisting_notification_of_same_type = existing_notifications.find { |n| n.notification_type == type }- return if existing_notification_of_same_type && !should_notify_previous?(user, post, existing_notification_of_same_type, opts)+ return if existing_notifications.present? && !should_notify_previous?(user, post, existing_notification_of_same_type, opts)notification_data = {}diff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rbindex 301f16fadd0..4a73313c7b1 100644--- a/spec/services/post_alerter_spec.rb+++ b/spec/services/post_alerter_spec.rb@@ -165,9 +165,11 @@ describe PostAlerter doendcontext 'quotes' do+ let(:category) { Fabricate(:category) }+ let(:topic) { Fabricate(:topic, category: category) }it 'does not notify for muted users' do- post = Fabricate(:post, raw: '[quote="EvilTrout, post:1"]whatup[/quote]')+ post = Fabricate(:post, raw: '[quote="EvilTrout, post:1"]whatup[/quote]', topic: topic)MutedUser.create!(user_id: evil_trout.id, muted_user_id: post.user_id)expect {@@ -176,7 +178,7 @@ describe PostAlerter doendit 'does not notify for ignored users' do- post = Fabricate(:post, raw: '[quote="EvilTrout, post:1"]whatup[/quote]')+ post = Fabricate(:post, raw: '[quote="EvilTrout, post:1"]whatup[/quote]', topic: topic)IgnoredUser.create!(user_id: evil_trout.id, ignored_user_id: post.user_id)expect {@@ -184,9 +186,27 @@ describe PostAlerter do}.to change(evil_trout.notifications, :count).by(0)end- it 'does not collapse quote notifications' do- topic = Fabricate(:topic)+ it 'does not notify for users with new reply notification' do+ post = Fabricate(:post, raw: '[quote="EvilTrout, post:1"]whatup[/quote]', topic: topic)+ notification = Notification.create!(topic: post.topic,+ post_number: post.post_number,+ read: false,+ notification_type: Notification.types[:replied],+ user: evil_trout,+ data: { topic_title: "test topic" }.to_json+ )++ expect {+ PostAlerter.post_created(post)+ }.to change(evil_trout.notifications, :count).by(0)+ notification.destroy+ expect {+ PostAlerter.post_created(post)+ }.to change(evil_trout.notifications, :count).by(1)+ end++ it 'does not collapse quote notifications' doexpect {2.times docreate_post_with_alerts(