DEV: Move autotag to topic creator (#12790)

This move was necessary to automatically tag the topic with the right
tags from creation time. The process post job may be delayed for a
short time.
This commit is contained in:
Bianca Nenciu
2021-04-23 16:55:34 +03:00
committed by GitHub
parent a97e3e249d
commit 8c4a11c006
4 changed files with 43 additions and 63 deletions

View File

@ -176,6 +176,16 @@ class TopicCreator
topic.errors.add(:base, :unable_to_tag)
rollback_from_errors!(topic)
end
guardian = Guardian.new(Discourse.system_user)
word_watcher = WordWatcher.new("#{@opts[:title]} #{@opts[:raw]}")
word_watcher_tags = topic.tags.map(&:name)
WordWatcher.words_for_action(:tag).each do |word, tags|
if word_watcher.matches?(word)
word_watcher_tags += tags.split(",")
end
end
DiscourseTagging.tag_topic_by_names(topic, guardian, word_watcher_tags)
end
def setup_auto_close_time(topic)