A platform for community discussion. Free, open, simple.
FIX: Notify tag watchers when publishing topic (#17576)
Bianca Nenciuf75a99e93295
diff --git a/app/jobs/regular/notify_tag_change.rb b/app/jobs/regular/notify_tag_change.rbindex 6e45c24d57b..0fcbbc621e8 100644--- a/app/jobs/regular/notify_tag_change.rb+++ b/app/jobs/regular/notify_tag_change.rb@@ -3,7 +3,7 @@module Jobsclass NotifyTagChange < ::Jobs::Basedef execute(args)- return if SiteSetting.disable_tags_edit_notifications+ return if SiteSetting.disable_tags_edit_notifications && !args[:force]post = Post.find_by(id: args[:post_id])diff --git a/lib/topic_publisher.rb b/lib/topic_publisher.rbindex 63afb8dede5..9c812ec0009 100644--- a/lib/topic_publisher.rb+++ b/lib/topic_publisher.rb@@ -46,6 +46,14 @@ class TopicPublisherendend+ Jobs.enqueue(+ :notify_tag_change,+ post_id: @topic.first_post.id,+ notified_user_ids: [@topic.first_post.user_id, @published_by.id].uniq,+ diff_tags: @topic.tags.map(&:name),+ force: true,+ )+MessageBus.publish("/topic/#{@topic.id}", reload_topic: true, refresh_stream: true)@topicdiff --git a/spec/lib/topic_publisher_spec.rb b/spec/lib/topic_publisher_spec.rbindex 10e02094016..04847b8f0d8 100644--- a/spec/lib/topic_publisher_spec.rb+++ b/spec/lib/topic_publisher_spec.rb@@ -16,6 +16,8 @@ describe TopicPublisher dofab!(:shared_draft) { Fabricate(:shared_draft, topic: topic, category: category) }fab!(:moderator) { Fabricate(:moderator) }fab!(:op) { Fabricate(:post, topic: topic) }+ fab!(:user) { Fabricate(:user) }+ fab!(:tag) { Fabricate(:tag) }before do# Create a revision@@ -51,6 +53,24 @@ describe TopicPublisher doexpect(op.last_version_at).to eq_time(published_at)endend++ it "will notify users watching tag" do+ Jobs.run_immediately!++ TagUser.create!(+ user_id: user.id,+ tag_id: tag.id,+ notification_level: NotificationLevels.topic_levels[:watching]+ )++ topic.update!(tags: [tag])++ expect { TopicPublisher.new(topic, moderator, shared_draft.category_id).publish! }+ .to change { Notification.count }.by(1)++ topic.reload+ expect(topic.tags).to contain_exactly(tag)+ endendend