A platform for community discussion. Free, open, simple.
FIX: suppress notification flood when post is edited (#8838)
Krzysztof Kotlarek5b03f35614fe
diff --git a/app/services/post_alerter.rb b/app/services/post_alerter.rbindex c66619dcc26..7bff7d68195 100644--- a/app/services/post_alerter.rb+++ b/app/services/post_alerter.rb@@ -248,8 +248,8 @@ class PostAlerter# TODO decide if it makes sense to also publish a desktop notificationend- def should_notify_edit?(notification, opts)- notification.data_hash["display_username"] != opts[:display_username]+ def should_notify_edit?(notification, post, opts)+ notification.data_hash["display_username"] != (opts[:display_username].presence || post.user.username)enddef should_notify_like?(user, notification)@@ -258,9 +258,9 @@ class PostAlerterfalseend- def should_notify_previous?(user, notification, opts)+ def should_notify_previous?(user, post, notification, opts)case notification.notification_type- when Notification.types[:edited] then should_notify_edit?(notification, opts)+ when Notification.types[:edited] then should_notify_edit?(notification, post, opts)when Notification.types[:liked] then should_notify_like?(user, notification)else falseend@@ -328,7 +328,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, existing_notification_of_same_type, opts)+ return if existing_notification_of_same_type && !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 c98125a521a..301f16fadd0 100644--- a/spec/services/post_alerter_spec.rb+++ b/spec/services/post_alerter_spec.rb@@ -1095,4 +1095,19 @@ describe PostAlerter doendendend++ describe '#notify_post_users' do+ fab!(:topic) { Fabricate(:topic) }+ fab!(:post) { Fabricate(:post, topic: topic) }++ it 'creates single edit notification when post is modified' do+ TopicUser.create!(user_id: user.id, topic_id: topic.id, notification_level: TopicUser.notification_levels[:watching], highest_seen_post_number: post.post_number)+ PostAlerter.new.notify_post_users(post, [])+ expect(Notification.count).to eq(1)+ expect(Notification.last.notification_type).to eq(Notification.types[:edited])++ PostAlerter.new.notify_post_users(post, [])+ expect(Notification.count).to eq(1)+ end+ endend