DEV: remove unnecessary safe nav operators (#6730)

DEV: remove unnecessary safe nav operators (#6730)
From 57ba4b7cb2fca06beba58f5ee0f585fb2f93f579 Mon Sep 17 00:00:00 2001
From: Vinoth Kannan <vinothkannan@vinkas.com>
Date: Wed, 5 Dec 2018 20:07:18 +0530
Subject: [PATCH] DEV: remove unnecessary safe nav operators (#6730)


diff --git a/app/models/web_hook.rb b/app/models/web_hook.rb
index dc8a21d..b2fe649 100644
--- a/app/models/web_hook.rb
+++ b/app/models/web_hook.rb
@@ -66,27 +66,27 @@ class WebHook < ActiveRecord::Base
   end
 
   def self.enqueue_topic_hooks(event, topic)
-    if active_web_hooks('topic').exists?
+    if active_web_hooks('topic').exists? && topic.present?
       topic_view = TopicView.new(topic.id, Discourse.system_user)
       payload = WebHook.generate_payload(:topic, topic_view, WebHookTopicViewSerializer)
 
       WebHook.enqueue_hooks(:topic, event,
         id: topic.id,
-        category_id: topic&.category_id,
-        tag_ids: topic&.tags&.pluck(:id),
+        category_id: topic.category_id,
+        tag_ids: topic.tags.pluck(:id),
         payload: payload
       )
     end
   end
 
   def self.enqueue_post_hooks(event, post)
-    if active_web_hooks('post').exists?
+    if active_web_hooks('post').exists? && post.present?
       payload = WebHook.generate_payload(:post, post)
 
       WebHook.enqueue_hooks(:post, event,
         id: post.id,
-        category_id: post&.topic&.category_id,
-        tag_ids: post&.topic&.tags&.pluck(:id),
+        category_id: post.topic&.category_id,
+        tag_ids: post.topic&.tags&.pluck(:id),
         payload: payload
       )
     end

GitHub

2 Likes