From 431503bae2dc6e12bdade7d5d20f707112c2f7c2 Mon Sep 17 00:00:00 2001
From: David Yip <yipdw@member.fsf.org>
Date: Mon, 6 Nov 2017 16:48:36 -0600
Subject: [PATCH] Also run the keyword matcher on a status' tags.  #208.

---
 app/lib/feed_manager.rb       |  8 ++++++--
 spec/lib/feed_manager_spec.rb | 16 ++++++++++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb
index 3b16b5d528..414632a8a9 100644
--- a/app/lib/feed_manager.rb
+++ b/app/lib/feed_manager.rb
@@ -173,10 +173,14 @@ class FeedManager
   def keyword_filter?(status, matcher)
     should_filter   = matcher =~ status.text
     should_filter ||= matcher =~ status.spoiler_text
+    should_filter ||= status.tags.find_each.any? { |t| matcher =~ t.name }
 
     if status.reblog?
-      should_filter ||= matcher =~ status.reblog.text
-      should_filter ||= matcher =~ status.reblog.spoiler_text
+      reblog = status.reblog
+
+      should_filter ||= matcher =~ reblog.text
+      should_filter ||= matcher =~ reblog.spoiler_text
+      should_filter ||= reblog.tags.find_each.any? { |t| matcher =~ t.name }
     end
 
     !!should_filter
diff --git a/spec/lib/feed_manager_spec.rb b/spec/lib/feed_manager_spec.rb
index 715d853067..0e49684407 100644
--- a/spec/lib/feed_manager_spec.rb
+++ b/spec/lib/feed_manager_spec.rb
@@ -164,6 +164,22 @@ RSpec.describe FeedManager do
 
         expect(FeedManager.instance.filter?(:home, reblog, alice.id)).to be true
       end
+
+      it 'returns true for a status with a tag that matches a muted keyword' do
+        Fabricate('Glitch::KeywordMute', account: alice, keyword: 'jorts')
+        status = Fabricate(:status, account: bob)
+	status.tags << Fabricate(:tag, name: 'jorts')
+
+        expect(FeedManager.instance.filter?(:home, status, alice.id)).to be true
+      end
+
+      it 'returns true for a status with a tag that matches an octothorpe-prefixed muted keyword' do
+        Fabricate('Glitch::KeywordMute', account: alice, keyword: '#jorts')
+        status = Fabricate(:status, account: bob)
+	status.tags << Fabricate(:tag, name: 'jorts')
+
+        expect(FeedManager.instance.filter?(:home, status, alice.id)).to be true
+      end
     end
 
     context 'for mentions feed' do