FIX: On tag change notify only users watching the tag. (#7707)

This commit is contained in:
Bianca Nenciu 2019-06-11 18:06:54 +03:00 committed by GitHub
parent 1881e895dc
commit 934adb14d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 5 deletions

View File

@ -9,7 +9,6 @@ module Jobs
if post&.topic&.visible?
post_alerter = PostAlerter.new
post_alerter.notify_post_users(post, User.where(id: args[:notified_user_ids]))
post_alerter.notify_first_post_watchers(post, post_alerter.tag_watchers(post.topic))
end
end

View File

@ -94,8 +94,7 @@ class PostRevisor
tc.record_change('tags', prev_tags, tags)
DB.after_commit do
post = tc.topic.ordered_posts.first
notified_user_ids = [post.user_id, post.last_editor_id].uniq
Jobs.enqueue(:notify_tag_change, post_id: post.id, notified_user_ids: notified_user_ids)
Jobs.enqueue(:notify_tag_change, post_id: post.id)
end
end
end

View File

@ -989,15 +989,16 @@ describe PostAlerter do
SiteSetting.tagging_enabled = true
Jobs.run_immediately!
TagUser.change(user.id, watched_tag.id, TagUser.notification_levels[:watching_first_post])
TopicUser.change(Fabricate(:user).id, post.topic.id, notification_level: TopicUser.notification_levels[:watching])
end
it "triggers a notification" do
expect(user.notifications.where(notification_type: Notification.types[:watching_first_post]).count).to eq(0)
PostRevisor.new(post).revise!(Fabricate(:user), tags: [other_tag.name, watched_tag.name])
expect { PostRevisor.new(post).revise!(Fabricate(:user), tags: [other_tag.name, watched_tag.name]) }.to change { Notification.count }.by(1)
expect(user.notifications.where(notification_type: Notification.types[:watching_first_post]).count).to eq(1)
PostRevisor.new(post).revise!(Fabricate(:user), tags: [watched_tag.name, other_tag.name])
expect { PostRevisor.new(post).revise!(Fabricate(:user), tags: [watched_tag.name, other_tag.name]) }.to change { Notification.count }.by(0)
expect(user.notifications.where(notification_type: Notification.types[:watching_first_post]).count).to eq(1)
end