A platform for community discussion. Free, open, simple.
FEATURE: add tracked filter to topic lists
Sam Saffron88dcdf776bf1
diff --git a/lib/topic_query.rb b/lib/topic_query.rbindex f030c83abae..a838e79e174 100644--- a/lib/topic_query.rb+++ b/lib/topic_query.rb@@ -824,6 +824,33 @@ class TopicQueryaction: action)end++ if filter == "tracked"+ sql = +<<~SQL+ topics.category_id IN (+ SELECT cu.category_id FROM category_users cu+ WHERE cu.user_id = :user_id AND cu.notification_level >= :tracking+ )+ SQL++ if SiteSetting.tagging_enabled+ sql << <<~SQL+ OR topics.id IN (+ SELECT tt.topic_id FROM topic_tags tt WHERE tt.tag_id IN (+ SELECT tu.tag_id+ FROM tag_users tu+ WHERE tu.user_id = :user_id AND tu.notification_level >= :tracking+ )+ )+ SQL+ end++ result = result.where(+ sql,+ user_id: @user.id,+ tracking: NotificationLevels.all[:tracking]+ )+ endendresult = result.where('topics.deleted_at IS NULL') if require_deleted_clausediff --git a/spec/components/topic_query_spec.rb b/spec/components/topic_query_spec.rbindex 6d97abfcb9c..fdfd67dabbd 100644--- a/spec/components/topic_query_spec.rb+++ b/spec/components/topic_query_spec.rb@@ -118,6 +118,39 @@ describe TopicQuery doendend+ context 'tracked' do+ it "filters tracked topics correctly" do+ SiteSetting.tagging_enabled = true++ tag = Fabricate(:tag)+ Fabricate(:topic, tags: [tag])+ topic2 = Fabricate(:topic)++ query = TopicQuery.new(user, filter: 'tracked').list_latest+ expect(query.topics.length).to eq(0)++ TagUser.create!(+ tag_id: tag.id,+ user_id: user.id,+ notification_level: NotificationLevels.all[:watching]+ )++ cu = CategoryUser.create!(+ category_id: topic2.category_id,+ user_id: user.id,+ notification_level: NotificationLevels.all[:regular]+ )++ query = TopicQuery.new(user, filter: 'tracked').list_latest+ expect(query.topics.length).to eq(1)++ cu.update!(notification_level: NotificationLevels.all[:tracking])++ query = TopicQuery.new(user, filter: 'tracked').list_latest+ expect(query.topics.length).to eq(2)+ end+ end+context 'deleted filter' doit "filters deleted topics correctly" do_topic = Fabricate(:topic, deleted_at: 1.year.ago)