From 87b4246c14eccb77a67839c727c336b224fb584b Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Tue, 19 Sep 2017 15:51:10 +0200 Subject: [PATCH] FIX: notify about whispered reply --- app/services/post_alerter.rb | 6 ++++- spec/services/post_alerter_spec.rb | 40 ++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/app/services/post_alerter.rb b/app/services/post_alerter.rb index 130eec12850..a3c7e7a4540 100644 --- a/app/services/post_alerter.rb +++ b/app/services/post_alerter.rb @@ -37,6 +37,10 @@ class PostAlerter allowed_group_users(post) end + def notify_about_reply?(post) + post.post_type == Post.types[:regular] || post.post_type == Post.types[:whisper] + end + def after_save_post(post, new_record = false) notified = [post.user] @@ -65,7 +69,7 @@ class PostAlerter # replies reply_to_user = post.reply_notification_target - if new_record && reply_to_user && !notified.include?(reply_to_user) && post.post_type == Post.types[:regular] + if new_record && reply_to_user && !notified.include?(reply_to_user) && notify_about_reply?(post) notify_non_pm_users(reply_to_user, :replied, post) notified += [reply_to_user] end diff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rb index ea47e4cf700..974e6bedc42 100644 --- a/spec/services/post_alerter_spec.rb +++ b/spec/services/post_alerter_spec.rb @@ -533,6 +533,46 @@ describe PostAlerter do end expect(events).to include(event_name: :before_create_notifications_for_users, params: [[user], reply]) end + + it "notifies about regular reply" do + user = Fabricate(:user) + topic = Fabricate(:topic) + post = Fabricate(:post, user: user, topic: topic) + + reply = Fabricate(:post, topic: topic, reply_to_post_number: 1) + PostAlerter.post_created(reply) + + expect(user.notifications.where(notification_type: Notification.types[:replied]).count).to eq(1) + end + + it "doesn't notify regular user about whispered reply" do + user = Fabricate(:user) + admin = Fabricate(:admin) + + topic = Fabricate(:topic) + post = Fabricate(:post, user: user, topic: topic) + + whispered_reply = Fabricate(:post, user: admin, topic: topic, post_type: Post.types[:whisper], reply_to_post_number: 1) + PostAlerter.post_created(whispered_reply) + + expect(user.notifications.where(notification_type: Notification.types[:replied]).count).to eq(0) + end + + it "notifies staff user about whispered reply" do + user = Fabricate(:user) + admin1 = Fabricate(:admin) + admin2 = Fabricate(:admin) + + topic = Fabricate(:topic) + post = Fabricate(:post, user: user, topic: topic) + + whispered_reply1 = Fabricate(:post, user: admin1, topic: topic, post_type: Post.types[:whisper], reply_to_post_number: 1) + whispered_reply2 = Fabricate(:post, user: admin2, topic: topic, post_type: Post.types[:whisper], reply_to_post_number: 2) + PostAlerter.post_created(whispered_reply1) + PostAlerter.post_created(whispered_reply2) + + expect(admin1.notifications.where(notification_type: Notification.types[:replied]).count).to eq(1) + end end context "watching" do