A platform for community discussion. Free, open, simple.
FIX: missing edit notifications in some rare cases
Sam Saffron3d0ccf864243
diff --git a/app/services/post_alerter.rb b/app/services/post_alerter.rbindex ae560ec2fd9..7b1965b60a4 100644--- a/app/services/post_alerter.rb+++ b/app/services/post_alerter.rb@@ -8,6 +8,11 @@ class PostAlerterpostend+ def self.post_edited(post, opts = {})+ PostAlerter.new(opts).after_save_post(post, false)+ post+ end+def initialize(default_opts = {})@default_opts = default_optsend@@ -261,7 +266,6 @@ 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)@@ -331,7 +335,14 @@ 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_notifications.present? && !should_notify_previous?(user, post, existing_notification_of_same_type, opts)+ if existing_notification_of_same_type && !should_notify_previous?(user, post, existing_notification_of_same_type, opts)+ return+ end++ # linked, quoted, mentioned may be suppressed if you already have a reply notification+ if type == Notification.types[:quoted] || type == Notification.types[:linked] || type == Notification.types[:mentioned]+ return if existing_notifications.find { |n| n.notification_type == Notification.types[:replied] }+ endnotification_data = {}diff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rbindex 973f31c6638..2b3734f1238 100644--- a/spec/services/post_alerter_spec.rb+++ b/spec/services/post_alerter_spec.rb@@ -110,7 +110,15 @@ describe PostAlerter doadmin = Fabricate(:admin)post.revise(admin, raw: 'I made a revision')- # skip this notification cause we already notified on a similar edit+ # lets also like this post which should trigger a notification+ PostActionCreator.new(+ admin,+ post,+ PostActionType.types[:like]+ ).perform++ # skip this notification cause we already notified on an edit by the same user+ # in the previous editfreeze_time 2.hours.from_nowpost.revise(admin, raw: 'I made another revision')@@ -119,7 +127,7 @@ describe PostAlerter dofreeze_time 2.hours.from_nowpost.revise(admin, raw: 'I made another revision')- expect(Notification.where(post_number: 1, topic_id: post.topic_id).count).to eq(3)+ expect(Notification.where(post_number: 1, topic_id: post.topic_id).count).to eq(4)endit 'notifies flaggers when flagged post gets unhidden by edit' do@@ -195,14 +203,13 @@ describe PostAlerter douser: evil_trout,data: { topic_title: "test topic" }.to_json)-expect {- PostAlerter.post_created(post)+ PostAlerter.post_edited(post)}.to change(evil_trout.notifications, :count).by(0)notification.destroyexpect {- PostAlerter.post_created(post)+ PostAlerter.post_edited(post)}.to change(evil_trout.notifications, :count).by(1)end