From 17b51bb465bb284a8496eb89d7b29fa3835f8a94 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Mon, 8 Aug 2016 15:14:18 -0400 Subject: [PATCH] FIX: topics tagged with muted tags should not be included in digest emails --- app/models/topic.rb | 7 +++++++ spec/models/topic_spec.rb | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/app/models/topic.rb b/app/models/topic.rb index ce5b9c6ae..20745168b 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -361,6 +361,13 @@ class Topic < ActiveRecord::Base topics = topics.where("topics.category_id NOT IN (?)", muted_category_ids) end + # Remove muted categories + muted_tag_ids = TagUser.lookup(user, :muted).pluck(:tag_id) + unless muted_tag_ids.empty? + topics = topics.joins("LEFT OUTER JOIN topic_tags ON topic_tags.topic_id = topics.id") + .where("topic_tags.tag_id NOT IN (?)", muted_tag_ids) + end + topics end diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 36b6376b4..9bac6b934 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -1364,6 +1364,24 @@ describe Topic do expect(Topic.for_digest(u, 1.year.ago, top_order: true)).to eq([topic]) end + it "doesn't return topics with only muted tags" do + user = Fabricate(:user) + tag = Fabricate(:tag) + TagUser.change(user.id, tag.id, TagUser.notification_levels[:muted]) + topic = Fabricate(:topic, tags: [tag]) + + expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to be_blank + end + + it "returns topics with both muted and not muted tags" do + user = Fabricate(:user) + muted_tag, other_tag = Fabricate(:tag), Fabricate(:tag) + TagUser.change(user.id, muted_tag.id, TagUser.notification_levels[:muted]) + topic = Fabricate(:topic, tags: [muted_tag, other_tag]) + + expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to eq([topic]) + end + end describe 'secured' do