diff --git a/app/jobs/regular/notify_tag_change.rb b/app/jobs/regular/notify_tag_change.rb index 6e45c24d57b..0fcbbc621e8 100644 --- a/app/jobs/regular/notify_tag_change.rb +++ b/app/jobs/regular/notify_tag_change.rb @@ -3,7 +3,7 @@ module Jobs class NotifyTagChange < ::Jobs::Base def 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.rb index 63afb8dede5..9c812ec0009 100644 --- a/lib/topic_publisher.rb +++ b/lib/topic_publisher.rb @@ -46,6 +46,14 @@ class TopicPublisher end end + 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) @topic diff --git a/spec/lib/topic_publisher_spec.rb b/spec/lib/topic_publisher_spec.rb index 10e02094016..04847b8f0d8 100644 --- a/spec/lib/topic_publisher_spec.rb +++ b/spec/lib/topic_publisher_spec.rb @@ -16,6 +16,8 @@ describe TopicPublisher do fab!(: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 do expect(op.last_version_at).to eq_time(published_at) end end + + 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) + end end end