mirror of
https://github.com/discourse/discourse.git
synced 2025-06-01 09:08:10 +08:00
FIX: Do not create a double like notification. (#7999)
When a user liked, unliked and liked again the same post, the poster would receive a notification such as "X and X liked ...". This happened because PostActionNotifier.post_action_created was called twice.
This commit is contained in:
@ -205,7 +205,6 @@ private
|
|||||||
post_action.recover!
|
post_action.recover!
|
||||||
action_attrs.each { |attr, val| post_action.public_send("#{attr}=", val) }
|
action_attrs.each { |attr, val| post_action.public_send("#{attr}=", val) }
|
||||||
post_action.save
|
post_action.save
|
||||||
PostActionNotifier.post_action_created(post_action)
|
|
||||||
else
|
else
|
||||||
post_action = PostAction.create(where_attrs.merge(action_attrs))
|
post_action = PostAction.create(where_attrs.merge(action_attrs))
|
||||||
if post_action && post_action.errors.count == 0
|
if post_action && post_action.errors.count == 0
|
||||||
|
@ -65,6 +65,20 @@ describe PostActionCreator do
|
|||||||
result = PostActionCreator.new(user, nil, like_type_id).perform
|
result = PostActionCreator.new(user, nil, like_type_id).perform
|
||||||
expect(result.failed?).to eq(true)
|
expect(result.failed?).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'does not create a double like notification' do
|
||||||
|
PostActionNotifier.enable
|
||||||
|
post.user.user_option.update!(like_notification_frequency: UserOption.like_notification_frequency_type[:always])
|
||||||
|
|
||||||
|
expect(PostActionCreator.new(user, post, like_type_id).perform.success).to eq(true)
|
||||||
|
expect(PostActionDestroyer.new(user, post, like_type_id).perform.success).to eq(true)
|
||||||
|
expect(PostActionCreator.new(user, post, like_type_id).perform.success).to eq(true)
|
||||||
|
|
||||||
|
notification = Notification.last
|
||||||
|
notification_data = JSON.parse(notification.data)
|
||||||
|
expect(notification_data['display_username']).to eq(user.username)
|
||||||
|
expect(notification_data['username2']).to eq(nil)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "flags" do
|
context "flags" do
|
||||||
|
Reference in New Issue
Block a user