REFACTOR: post_destroyer destroy method (#8462)
diff --git a/lib/post_destroyer.rb b/lib/post_destroyer.rb
index 2b74d83791..4e09ed8f88 100644
--- a/lib/post_destroyer.rb
+++ b/lib/post_destroyer.rb
@@ -56,8 +56,9 @@ class PostDestroyer
def destroy
payload = WebHook.generate_payload(:post, @post) if WebHook.active_web_hooks(:post).exists?
topic = @post.topic
+ is_first_post = @post.is_first_post? && topic
- if @post.is_first_post? && topic
+ if is_first_post
topic_view = TopicView.new(topic.id, Discourse.system_user)
topic_payload = WebHook.generate_payload(:topic, topic_view, WebHookTopicViewSerializer) if WebHook.active_web_hooks(:topic).exists?
end
@@ -75,10 +76,10 @@ class PostDestroyer
DiscourseEvent.trigger(:post_destroyed, @post, @opts, @user)
WebHook.enqueue_post_hooks(:post_destroyed, @post, payload)
- if @post.is_first_post? && @post.topic
- UserActionManager.topic_destroyed(@post.topic)
- DiscourseEvent.trigger(:topic_destroyed, @post.topic, @user)
- WebHook.enqueue_topic_hooks(:topic_destroyed, @post.topic, topic_payload)
+ if is_first_post
+ UserActionManager.topic_destroyed(topic)
+ DiscourseEvent.trigger(:topic_destroyed, topic, @user)
+ WebHook.enqueue_topic_hooks(:topic_destroyed, topic, topic_payload)
end
end
GitHub sha: a54aaeeb