FIX: Include topics from subcategories in tracked list (#10850)

FIX: Include topics from subcategories in tracked list (#10850)

diff --git a/lib/topic_query.rb b/lib/topic_query.rb
index b765e61..fb6ff57 100644
--- a/lib/topic_query.rb
+++ b/lib/topic_query.rb
@@ -400,6 +400,12 @@ class TopicQuery
         SELECT cu.category_id FROM category_users cu
         WHERE cu.user_id = :user_id AND cu.notification_level >= :tracking
       )
+      OR topics.category_id IN (
+        SELECT c.id FROM categories c WHERE c.parent_category_id IN (
+          SELECT cd.category_id FROM category_users cd
+          WHERE cd.user_id = :user_id AND cd.notification_level >= :tracking
+        )
+      )
     SQL
 
     if SiteSetting.tagging_enabled
diff --git a/spec/components/topic_query_spec.rb b/spec/components/topic_query_spec.rb
index 31ade88..fdb0598 100644
--- a/spec/components/topic_query_spec.rb
+++ b/spec/components/topic_query_spec.rb
@@ -148,6 +148,20 @@ describe TopicQuery do
 
       query = TopicQuery.new(user, filter: 'tracked').list_latest
       expect(query.topics.length).to eq(2)
+
+      # includes subcategories of tracked categories
+      parentcat = Fabricate(:category)
+      subcat = Fabricate(:category, parent_category_id: parentcat.id)
+      topic3 = Fabricate(:topic, category_id: subcat.id)
+
+      CategoryUser.create!(
+        category_id: parentcat.id,
+        user_id: user.id,
+        notification_level: NotificationLevels.all[:tracking]
+      )
+
+      query = TopicQuery.new(user, filter: 'tracked').list_latest
+      expect(query.topics.length).to eq(3)
     end
   end
 

GitHub sha: 2ad7d989

This commit appears in #10850 which was approved by eviltrout. It was merged by pmusaraj.