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.
This commit is contained in:
Bianca Nenciu 2021-04-07 00:01:15 +03:00 committed by GitHub
parent 34596beb52
commit 1682827f67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -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

View File

@ -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)