FIX: Include watched topics from muted categories in digests (#12602)

FIX: Include watched topics from muted categories in digests (#12602)

Topic that are muted or from muted categories are not included in digests, but non-muted topics from muted categories should be included.

diff --git a/app/models/topic.rb b/app/models/topic.rb
index ff605b7..18cb65f 100644
--- a/app/models/topic.rb
+++ b/app/models/topic.rb
@@ -506,7 +506,7 @@ class Topic < ActiveRecord::Base
     end
     if remove_category_ids.present?
       remove_category_ids.uniq!
-      topics = topics.where("topics.category_id NOT IN (?)", remove_category_ids)
+      topics = topics.where("topic_users.notification_level != ? OR topics.category_id NOT IN (?)", TopicUser.notification_levels[:muted], remove_category_ids)
     end
 
     # Remove muted tags
diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb
index 13447a0..e35ee4e 100644
--- a/spec/models/topic_spec.rb
+++ b/spec/models/topic_spec.rb
@@ -1952,6 +1952,17 @@ describe Topic do
         expect(Topic.for_digest(user, 1.year.ago)).to eq([])
       end
 
+      it "does return watched topics from muted categories" do
+        user = Fabricate(:user)
+        category = Fabricate(:category_with_definition, created_at: 2.minutes.ago)
+        topic = Fabricate(:topic, category: category, created_at: 1.minute.ago)
+
+        CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:muted], category.id)
+        Fabricate(:topic_user, user: user, topic: topic, notification_level: TopicUser.notification_levels[:regular])
+
+        expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to eq([topic])
+      end
+
       it "doesn't return topics from suppressed categories" do
         user = Fabricate(:user)
         category = Fabricate(:category_with_definition, created_at: 2.minutes.ago)

GitHub sha: 1682827f

1 Like

This commit appears in #12602 which was approved by eviltrout. It was merged by nbianca.