A platform for community discussion. Free, open, simple.
FIX: Exclude topics from ignored users in digest emails (#38866)
Régis Hanol35c30fc5518e
diff --git a/app/models/topic.rb b/app/models/topic.rbindex 337824436e3..9bba0c07a5a 100644--- a/app/models/topic.rb+++ b/app/models/topic.rb@@ -613,10 +613,9 @@ class Topic < ActiveRecord::Base# Remove muted and shared draft categoriesremove_category_ids =- CategoryUser.where(- user_id: user.id,- notification_level: CategoryUser.notification_levels[:muted],- ).pluck(:category_id)+ CategoryUser.where(user:, notification_level: CategoryUser.notification_levels[:muted]).pluck(+ :category_id,+ )remove_category_ids << SiteSetting.shared_drafts_category if SiteSetting.shared_drafts_enabled?@@ -630,6 +629,11 @@ class Topic < ActiveRecord::Base)end+ # Remove topics from ignored users+ ignored_user_ids =+ IgnoredUser.where(user:).where(expiring_at: Time.zone.now..).pluck(:ignored_user_id)+ topics = topics.where.not(user_id: ignored_user_ids) if ignored_user_ids.present?+# Remove muted tagsmuted_tag_ids = TagUser.lookup(user, :muted).pluck(:tag_id)unless muted_tag_ids.empty?@@ -637,8 +641,7 @@ class Topic < ActiveRecord::Base# and don't forget untagged topics.topics =topics.where(- "EXISTS ( SELECT 1 FROM topic_tags WHERE topic_tags.topic_id = topics.id AND tag_id NOT IN (?) )- OR NOT EXISTS (SELECT 1 FROM topic_tags WHERE topic_tags.topic_id = topics.id)",+ "EXISTS (SELECT 1 FROM topic_tags WHERE topic_tags.topic_id = topics.id AND tag_id NOT IN (?)) OR NOT EXISTS (SELECT 1 FROM topic_tags WHERE topic_tags.topic_id = topics.id)",muted_tag_ids,)enddiff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rbindex b6519fc3a06..dcfc428639e 100644--- a/spec/models/topic_spec.rb+++ b/spec/models/topic_spec.rb@@ -2460,6 +2460,14 @@ RSpec.describe Topic doexpect(Topic.for_digest(user, 1.year.ago)).to eq([])end+ it "doesn't return topics from ignored users" do+ ignored_user = Fabricate(:user)+ Fabricate(:topic, user: ignored_user, created_at: 1.minute.ago)+ Fabricate(:ignored_user, user:, ignored_user:, expiring_at: 2.months.from_now)++ expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to be_blank+ end+it "does return watched topics from muted categories" docategory = Fabricate(:category_with_definition, created_at: 2.minutes.ago)topic = Fabricate(:topic, category: category, created_at: 1.minute.ago)