about summary refs log tree commit diff
path: root/app/lib/feed_manager.rb
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-08-02 02:30:35 -0500
committermultiple creatures <dev@multiple-creature.party>2019-08-02 02:30:35 -0500
commit65c42e5398304273b54916cc90441ade23317d85 (patch)
tree466c63aa34c1680c49e66a3c7b0961297f1d8929 /app/lib/feed_manager.rb
parent3813810cac8eb138ed1819058d122503628d6cba (diff)
filters now have options to separately match post text, content warnings/titles, & hashtags + option to filter threads containing a matching post
Diffstat (limited to 'app/lib/feed_manager.rb')
-rw-r--r--app/lib/feed_manager.rb44
1 files changed, 8 insertions, 36 deletions
diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb
index 9996291c2..6d8f46e6f 100644
--- a/app/lib/feed_manager.rb
+++ b/app/lib/feed_manager.rb
@@ -5,6 +5,7 @@ require 'singleton'
 class FeedManager
   include Singleton
   include Redisable
+  include FilterHelper
 
   MAX_ITEMS = 1666
 
@@ -156,6 +157,7 @@ class FeedManager
   def filter_from_home?(status, receiver_id)
     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?)
+    return true  if filtering_thread?(receiver_id, status.conversation_id)
     return true  if phrase_filtered?(status, receiver_id, :home)
 
     check_for_blocks = status.active_mentions.pluck(:account_id)
@@ -168,12 +170,12 @@ class FeedManager
 
     return true if blocks_or_mutes?(receiver_id, check_for_blocks, :home)
 
-    if status.reply? && !status.in_reply_to_account_id.nil?                                                                      # Filter out if it's a reply
-      should_filter   = !Follow.where(account_id: receiver_id, target_account_id: status.in_reply_to_account_id).exists?         # and I'm not following the person it's a reply to
-      should_filter &&= receiver_id != status.in_reply_to_account_id                                                             # and it's not a reply to me
-      should_filter &&= status.account_id != status.in_reply_to_account_id                                                       # and it's not a self-reply
+    if status.reply? && !status.in_reply_to_account_id.nil? # Filter out if it's a reply
+      should_filter   = !Follow.where(account_id: receiver_id, target_account_id: status.in_reply_to_account_id).exists? # and I'm not following the person it's a reply to
+      should_filter &&= receiver_id != status.in_reply_to_account_id # and it's not a reply to me
+      should_filter &&= status.account_id != status.in_reply_to_account_id # and it's not a self-reply
       return should_filter
-    elsif status.reblog?                                                                                                         # Filter out a reblog
+    elsif status.reblog? # Filter out a reblog
       should_filter   = Follow.where(account_id: receiver_id, target_account_id: status.account_id, show_reblogs: false).exists? # if the reblogger's reblogs are suppressed
       should_filter ||= (status.reblog.account.silenced? && !Follow.where(account_id: receiver_id, target_account_id: status.reblog.account_id).exists?) # or if the account is silenced and I'm not following them
       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
@@ -186,6 +188,7 @@ class FeedManager
 
   def filter_from_mentions?(status, receiver_id)
     return true if receiver_id == status.account_id
+    return true if filtering_thread?(receiver_id, status.conversation_id)
     return true if phrase_filtered?(status, receiver_id, :notifications)
 
     # This filter is called from NotifyService, but already after the sender of
@@ -200,37 +203,6 @@ class FeedManager
     should_filter
   end
 
-  def phrase_filtered?(status, receiver_id, context)
-    active_filters = Rails.cache.fetch("filters:#{receiver_id}") { CustomFilter.where(account_id: receiver_id).active_irreversible.to_a }.to_a
-
-    active_filters.select! { |filter| filter.context.include?(context.to_s) && !filter.expired? }
-
-    if status.media_attachments.any?
-      active_filters.delete_if { |filter| filter.exclude_media }
-    else
-      active_filters.delete_if { |filter| filter.media_only }
-    end
-
-    active_filters.map! do |filter|
-      if filter.whole_word
-        sb = filter.phrase =~ /\A[[:word:]]/ ? '\b' : ''
-        eb = filter.phrase =~ /[[:word:]]\z/ ? '\b' : ''
-
-        /(?mix:#{sb}#{Regexp.escape(filter.phrase)}#{eb})/
-      else
-        /#{Regexp.escape(filter.phrase)}/i
-      end
-    end
-
-    return false if active_filters.empty?
-
-    combined_regex = active_filters.reduce { |memo, obj| Regexp.union(memo, obj) }
-    status         = status.reblog if status.reblog?
-
-    !combined_regex.match(Formatter.instance.plaintext(status)).nil? ||
-      (status.spoiler_text.present? && !combined_regex.match(status.spoiler_text).nil?)
-  end
-
   # Adds a status to an account's feed, returning true if a status was
   # added, and false if it was not added to the feed. Note that this is
   # an internal helper: callers must call trim or push updates if