mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 02:13:47 +08:00
FIX: suppress notification flood when post is edited (#8838)
This commit is contained in:
parent
6455c6ee87
commit
5b03f35614
|
@ -248,8 +248,8 @@ class PostAlerter
|
|||
# TODO decide if it makes sense to also publish a desktop notification
|
||||
end
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
def should_notify_like?(user, notification)
|
||||
|
@ -258,9 +258,9 @@ class PostAlerter
|
|||
false
|
||||
end
|
||||
|
||||
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 false
|
||||
end
|
||||
|
@ -328,7 +328,7 @@ class PostAlerter
|
|||
# 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 }
|
||||
|
||||
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 = {}
|
||||
|
||||
|
|
|
@ -1095,4 +1095,19 @@ describe PostAlerter do
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue
Block a user