FIX: Publish web hooks when topic archetype is converted.

This commit is contained in:
Guo Xiang Tan
2019-04-16 15:16:23 +08:00
parent 347663e852
commit 1056dd16d3
4 changed files with 54 additions and 32 deletions

View File

@@ -1402,6 +1402,14 @@ class Topic < ActiveRecord::Base
scores[0] >= SiteSetting.num_flaggers_to_close_topic && scores[1] >= SiteSetting.score_to_auto_close_topic
end
def update_category_topic_count_by(num)
if category_id.present?
Category
.where(['id = ?', category_id])
.update_all("topic_count = topic_count " + (num > 0 ? '+' : '') + "#{num}")
end
end
private
def invite_to_private_message(invited_by, target_user, guardian)
@@ -1453,12 +1461,6 @@ class Topic < ActiveRecord::Base
end
end
def update_category_topic_count_by(num)
if category_id.present?
Category.where(['id = ?', category_id]).update_all("topic_count = topic_count " + (num > 0 ? '+' : '') + "#{num}")
end
end
def limit_first_day_topics_per_day
apply_per_day_rate_limit_for("first-day-topics", :max_topics_in_first_day)
end

View File

@@ -9,7 +9,7 @@ class TopicConverter
def convert_to_public_topic(category_id = nil)
Topic.transaction do
@topic.category_id =
category_id =
if category_id
category_id
elsif SiteSetting.allow_uncategorized_topics
@@ -21,10 +21,15 @@ class TopicConverter
.pluck(:id).first
end
@topic.archetype = Archetype.default
@topic.save
PostRevisor.new(@topic.first_post, @topic).revise!(
@user,
{
category_id: category_id,
archetype: Archetype.default
}
)
update_user_stats
update_category_topic_count_by(1)
Jobs.enqueue(:topic_action_converter, topic_id: @topic.id)
watch_topic(topic)
@@ -34,11 +39,18 @@ class TopicConverter
def convert_to_private_message
Topic.transaction do
update_category_topic_count_by(-1)
@topic.category_id = nil
@topic.archetype = Archetype.private_message
@topic.update_category_topic_count_by(-1)
PostRevisor.new(@topic.first_post, @topic).revise!(
@user,
{
category_id: nil,
archetype: Archetype.private_message
}
)
add_allowed_users
@topic.save!
Jobs.enqueue(:topic_action_converter, topic_id: @topic.id)
watch_topic(topic)
end
@@ -71,6 +83,7 @@ class TopicConverter
# update topics count
@topic.user.user_stat.topic_count -= 1
@topic.user.user_stat.save!
@topic.save!
end
def watch_topic(topic)
@@ -82,10 +95,4 @@ class TopicConverter
end
end
def update_category_topic_count_by(num)
if @topic.category_id.present?
Category.where(['id = ?', @topic.category_id]).update_all("topic_count = topic_count " + (num > 0 ? '+' : '') + "#{num}")
end
end
end