From 53b7220638680e00594ca195753bed0277571341 Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Wed, 3 Nov 2021 12:47:09 +0530 Subject: [PATCH] FIX: exclude suppressed category topics in digest even if unmuted. (#14793) Previously, suppressed category topics are included in the digest emails if the user visited that topic before and the `TopicUser` record is created with any notification level except 'muted'. --- app/models/topic.rb | 2 +- spec/models/topic_spec.rb | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/topic.rb b/app/models/topic.rb index f79a177054e..3519a5e894c 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -511,7 +511,7 @@ class Topic < ActiveRecord::Base # Remove muted and shared draft categories remove_category_ids = CategoryUser.where(user_id: user.id, notification_level: CategoryUser.notification_levels[:muted]).pluck(:category_id) if SiteSetting.digest_suppress_categories.present? - remove_category_ids += SiteSetting.digest_suppress_categories.split("|").map(&:to_i) + topics = topics.where("topics.category_id NOT IN (?)", SiteSetting.digest_suppress_categories.split("|").map(&:to_i)) end if SiteSetting.shared_drafts_enabled? remove_category_ids << SiteSetting.shared_drafts_category diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 20d1721a8c7..de3086ed46d 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -2071,11 +2071,15 @@ describe Topic do it "doesn't return topics from suppressed categories" do user = Fabricate(:user) category = Fabricate(:category_with_definition, created_at: 2.minutes.ago) - Fabricate(:topic, category: category, created_at: 1.minute.ago) + topic = Fabricate(:topic, category: category, created_at: 1.minute.ago) SiteSetting.digest_suppress_categories = "#{category.id}" expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to be_blank + + 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 be_blank end it "doesn't return topics from TL0 users" do