mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: suppress notification flood when post is edited (#8838)
This commit is contained in:
committed by
GitHub
parent
6455c6ee87
commit
5b03f35614
@@ -248,8 +248,8 @@ class PostAlerter
|
|||||||
# TODO decide if it makes sense to also publish a desktop notification
|
# TODO decide if it makes sense to also publish a desktop notification
|
||||||
end
|
end
|
||||||
|
|
||||||
def should_notify_edit?(notification, opts)
|
def should_notify_edit?(notification, post, opts)
|
||||||
notification.data_hash["display_username"] != opts[:display_username]
|
notification.data_hash["display_username"] != (opts[:display_username].presence || post.user.username)
|
||||||
end
|
end
|
||||||
|
|
||||||
def should_notify_like?(user, notification)
|
def should_notify_like?(user, notification)
|
||||||
@@ -258,9 +258,9 @@ class PostAlerter
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def should_notify_previous?(user, notification, opts)
|
def should_notify_previous?(user, post, notification, opts)
|
||||||
case notification.notification_type
|
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)
|
when Notification.types[:liked] then should_notify_like?(user, notification)
|
||||||
else false
|
else false
|
||||||
end
|
end
|
||||||
@@ -328,7 +328,7 @@ class PostAlerter
|
|||||||
# Don't notify the same user about the same type of notification on the same post
|
# Don't notify the same user about the same type of notification on the same post
|
||||||
existing_notification_of_same_type = existing_notifications.find { |n| n.notification_type == type }
|
existing_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 = {}
|
notification_data = {}
|
||||||
|
|
||||||
|
|||||||
@@ -1095,4 +1095,19 @@ describe PostAlerter do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user