From 2b3dd1b94537ebeed9a9af0ec61f9263b68fbc11 Mon Sep 17 00:00:00 2001
From: romanrizzi <rizziromanalejandro@gmail.com>
Date: Thu, 29 Aug 2019 13:38:23 -0300
Subject: [PATCH] FIX: Avoid publishing changes if the topic was deleted

---
 app/models/topic_tracking_state.rb | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/app/models/topic_tracking_state.rb b/app/models/topic_tracking_state.rb
index ed8f347bd1a..3ed182ba213 100644
--- a/app/models/topic_tracking_state.rb
+++ b/app/models/topic_tracking_state.rb
@@ -345,7 +345,7 @@ SQL
   def self.publish_read_indicator_on_write(topic_id, last_read_post_number, user_id)
     topic = Topic.includes(:allowed_groups).select(:highest_post_number, :archetype, :id).find_by(id: topic_id)
 
-    if topic.private_message?
+    if topic&.private_message?
       groups = read_allowed_groups_of(topic)
       update_topic_list_read_indicator(topic, groups, topic.highest_post_number, user_id, true)
     end
@@ -354,7 +354,7 @@ SQL
   def self.publish_read_indicator_on_read(topic_id, last_read_post_number, user_id)
     topic = Topic.includes(:allowed_groups).select(:highest_post_number, :archetype, :id).find_by(id: topic_id)
 
-    if topic.private_message?
+    if topic&.private_message?
       groups = read_allowed_groups_of(topic)
       post = Post.find_by(topic_id: topic.id, post_number: last_read_post_number)
       trigger_post_read_count_update(post, groups)