]> cat aescling's git repositories - mastodon.git/commitdiff
Also run the keyword matcher on a status' tags. #208.
authorDavid Yip <yipdw@member.fsf.org>
Mon, 6 Nov 2017 22:48:36 +0000 (16:48 -0600)
committerDavid Yip <yipdw@member.fsf.org>
Thu, 16 Nov 2017 00:12:26 +0000 (18:12 -0600)
app/lib/feed_manager.rb
spec/lib/feed_manager_spec.rb

index 3b16b5d52821ef912432a1837bea2cfbeaa473a9..414632a8a94e5e4cb32c5a4ff1d6107365841e62 100644 (file)
@@ -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
index 715d853067a4036f5150c93d1dff6cd58a29e038..0e49684407ff58ad38c5ac5d6874345d1e675db9 100644 (file)
@@ -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