]> cat aescling's git repositories - mastodon.git/commitdiff
Apply keyword mutes to reblogs.
authorDavid Yip <yipdw@member.fsf.org>
Sat, 21 Oct 2017 20:44:47 +0000 (15:44 -0500)
committerDavid Yip <yipdw@member.fsf.org>
Sat, 21 Oct 2017 20:44:47 +0000 (15:44 -0500)
app/lib/feed_manager.rb
app/models/glitch/keyword_mute.rb
spec/fabricators/glitch_keyword_mute_fabricator.rb
spec/lib/feed_manager_spec.rb

index 1123f88bbdec7d42e50d4e1f9fdb002e34fdce11..576188324dbd43da6e157536e99c41d48f808f63 100644 (file)
@@ -138,7 +138,9 @@ class FeedManager
   end
 
   def filter_from_home?(status, receiver_id)
-    return true if Glitch::KeywordMute.matcher_for(receiver_id) =~ status.text
+    keyword_mute_matcher = Glitch::KeywordMute.matcher_for(receiver_id)
+
+    return true if keyword_mute_matcher =~ status.text
 
     return false if receiver_id == status.account_id
     return true  if status.reply? && (status.in_reply_to_id.nil? || status.in_reply_to_account_id.nil?)
@@ -161,6 +163,7 @@ class FeedManager
       return should_filter
     elsif status.reblog?                                                                                                 # Filter out a reblog
       should_filter   = Block.where(account_id: status.reblog.account_id, target_account_id: receiver_id).exists?        # or if the author of the reblogged status is blocking me
+      should_filter ||= keyword_mute_matcher.matches?(status.reblog.text)
       should_filter ||= AccountDomainBlock.where(account_id: receiver_id, domain: status.reblog.account.domain).exists?  # or the author's domain is blocked
       return should_filter
     end
index 3b0b47f52f3ca2c69e2299a048bc786d638ef8cd..823e252d3576c8047f1633951938852efc41b66b 100644 (file)
@@ -45,5 +45,9 @@ class Glitch::KeywordMute < ApplicationRecord
     def =~(str)
       regex ? regex =~ str : false
     end
+
+    def matches?(str)
+      !!(regex =~ str)
+    end
   end
 end
index 8601ed6d75a4174552126e96189d20b4164dd05b..20d393320d68b2ecba5a8585b1e7b17c978b784e 100644 (file)
@@ -1,2 +1,2 @@
-Fabricator(:glitch_keyword_mute) do
+Fabricator('Glitch::KeywordMute') do
 end
index 1861cc6edfb74dc178787249a3aba8cef6f4eafc..c9403d61670551820c3d65902dfde1161966ea0a 100644 (file)
@@ -119,6 +119,23 @@ RSpec.describe FeedManager do
         reblog = Fabricate(:status, reblog: status, account: jeff)
         expect(FeedManager.instance.filter?(:home, reblog, alice.id)).to be true
       end
+
+      it 'returns true for a status containing a muted keyword' do
+        Fabricate('Glitch::KeywordMute', account: alice, keyword: 'take')
+        alice.follow!(bob)
+        status = Fabricate(:status, text: 'This is a hot take', account: bob)
+
+        expect(FeedManager.instance.filter?(:home, status, alice.id)).to be true
+      end
+
+      it 'returns true for a reblog containing a muted keyword' do
+        Fabricate('Glitch::KeywordMute', account: alice, keyword: 'take')
+        alice.follow!(jeff)
+        status = Fabricate(:status, text: 'This is a hot take', account: bob)
+        reblog = Fabricate(:status, reblog: status, account: jeff)
+
+        expect(FeedManager.instance.filter?(:home, reblog, alice.id)).to be true
+      end
     end
 
     context 'for mentions feed' do
This page took 0.03221 seconds and 3 git commands to generate.