FIX: Only hide shared draft topics from `latest` (#6737)

FIX: Only hide shared draft topics from `latest` (#6737)

Previously we were hiding them from all topic lists, which can result in
topics being “stuck” in an unread state with no easy way to clear them.

From 6c71395bf64b2bf79e7bd81bc2fb0298af89a79b Mon Sep 17 00:00:00 2001
From: David Taylor <david@taylorhq.com>
Date: Fri, 7 Dec 2018 12:44:23 +0000
Subject: [PATCH] FIX: Only hide shared draft topics from `latest` (#6737)

Previously we were hiding them from all topic lists, which can result in
topics being "stuck" in an unread state with no easy way to clear them.

diff --git a/lib/topic_query.rb b/lib/topic_query.rb
index e0afa11..0e48e34 100644
--- a/lib/topic_query.rb
+++ b/lib/topic_query.rb
@@ -453,6 +453,7 @@ class TopicQuery
     result = remove_muted_topics(result, @user) unless options && options[:state] == "muted".freeze
     result = remove_muted_categories(result, @user, exclude: options[:category])
     result = remove_muted_tags(result, @user, options)
+    result = apply_shared_drafts(result, get_category_id(options[:category]), options)
 
     # plugins can remove topics here:
     self.class.results_filter_callbacks.each do |filter_callback|
@@ -694,7 +695,6 @@ class TopicQuery
 
     result = apply_ordering(result, options)
     result = result.listable_topics.includes(:category)
-    result = apply_shared_drafts(result, category_id, options)
 
     if options[:exclude_category_ids] && options[:exclude_category_ids].is_a?(Array) && options[:exclude_category_ids].size > 0
       result = result.where("categories.id NOT IN (?)", options[:exclude_category_ids].map(&:to_i)).references(:categories)
diff --git a/spec/components/topic_query_spec.rb b/spec/components/topic_query_spec.rb
index a524862..c7e8270 100644
--- a/spec/components/topic_query_spec.rb
+++ b/spec/components/topic_query_spec.rb
@@ -1026,5 +1026,20 @@ describe TopicQuery do
         expect(list.topics).not_to include(topic)
       end
     end
+
+    context "unread" do
+      let!(:partially_read) do
+        topic = Fabricate(:topic, category: shared_drafts_category)
+        Fabricate(:post, user: creator, topic: topic).topic
+        TopicUser.update_last_read(admin, topic.id, 0, 0, 0)
+        TopicUser.change(admin.id, topic.id, notification_level: TopicUser.notification_levels[:tracking])
+        topic
+      end
+
+      it 'does not remove topics from unread' do
+        expect(TopicQuery.new(admin).list_latest.topics).not_to include(partially_read) # Check we set up the topic/category correctly
+        expect(TopicQuery.new(admin).list_unread.topics).to include(partially_read)
+      end
+    end
   end
 end

GitHub

2 Likes