Skip to content

A platform for community discussion. Free, open, simple.

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

Penar Musaraj2ad7d98990a7
diff --git a/lib/topic_query.rb b/lib/topic_query.rb
index b765e610a35..fb6ff577b8b 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 31ade884680..fdb05980e24 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