about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/settings/preferences_controller.rb2
-rw-r--r--app/lib/feed_manager.rb22
-rw-r--r--app/lib/user_settings_decorator.rb5
-rw-r--r--app/models/user.rb5
-rw-r--r--app/views/settings/preferences/filters/show.html.haml3
5 files changed, 26 insertions, 11 deletions
diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb
index 9cb05ed7e..1bc66fb79 100644
--- a/app/controllers/settings/preferences_controller.rb
+++ b/app/controllers/settings/preferences_controller.rb
@@ -5,7 +5,6 @@ class Settings::PreferencesController < Settings::BaseController
 
   def update
     if user_settings.update(user_settings_params.to_h)
-      Rails.cache.delete("filter_settings:#{current_user.account_id}")
       ClearReblogsWorker.perform_async(current_user.account_id) if current_user.disables_home_reblogs?
     end
 
@@ -72,6 +71,7 @@ class Settings::PreferencesController < Settings::BaseController
       :setting_boost_every,
       :setting_boost_jitter,
       :setting_boost_random,
+      :setting_filter_unknown,
       :setting_unpublish_on_delete,
       :setting_rss_disabled,
       :setting_no_boosts_home,
diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb
index 9d6550c0d..892af9655 100644
--- a/app/lib/feed_manager.rb
+++ b/app/lib/feed_manager.rb
@@ -39,9 +39,9 @@ class FeedManager
   def filter?(timeline_type, status, receiver)
     case timeline_type
     when :home
-      filter_from_home?(status, receiver.id, build_crutches(receiver.id, [status]))
+      filter_from_home?(status, receiver.id, build_crutches(receiver.id, [status]), receiver.user&.filters_unknown?)
     when :list
-      filter_from_list?(status, receiver) || filter_from_home?(status, receiver.account_id, build_crutches(receiver.account_id, [status]))
+      filter_from_list?(status, receiver) || filter_from_home?(status, receiver.account_id, build_crutches(receiver.account_id, [status]), receiver.user&.filters_unknown?)
     when :mentions
       filter_from_mentions?(status, receiver.id)
     when :direct
@@ -148,6 +148,7 @@ class FeedManager
     timeline_key = key(:home, into_account.id)
     aggregate    = into_account.user&.aggregates_reblogs?
     no_reblogs   = into_account.user&.disables_home_reblogs?
+    no_unknown   = into_account.user&.filters_unknown?
     query        = from_account.statuses.where(visibility: [:public, :unlisted, :private]).includes(:preloadable_poll, reblog: :account).limit(FeedManager::MAX_ITEMS / 4)
 
     if redis.zcard(timeline_key) >= FeedManager::MAX_ITEMS / 4
@@ -159,7 +160,7 @@ class FeedManager
     crutches = build_crutches(into_account.id, statuses)
 
     statuses.each do |status|
-      next if filter_from_home?(status, into_account.id, crutches)
+      next if filter_from_home?(status, into_account.id, crutches, no_unknown)
 
       add_to_feed(:home, into_account.id, status, aggregate, no_reblogs)
     end
@@ -175,6 +176,7 @@ class FeedManager
     timeline_key = key(:list, list.id)
     aggregate    = list.account.user&.aggregates_reblogs?
     no_reblogs   = list.account.user&.disables_home_reblogs?
+    no_unknown   = list.account.user&.filters_unknown?
     query        = from_account.statuses.where(visibility: [:public, :unlisted, :private]).includes(:preloadable_poll, reblog: :account).limit(FeedManager::MAX_ITEMS / 4)
 
     if redis.zcard(timeline_key) >= FeedManager::MAX_ITEMS / 4
@@ -186,7 +188,7 @@ class FeedManager
     crutches = build_crutches(list.account_id, statuses)
 
     statuses.each do |status|
-      next if filter_from_home?(status, list.account_id, crutches) || filter_from_list?(status, list)
+      next if filter_from_home?(status, list.account_id, crutches, no_unknown) || filter_from_list?(status, list)
 
       add_to_feed(:list, list.id, status, aggregate, no_reblogs)
     end
@@ -276,7 +278,7 @@ class FeedManager
         crutches = build_crutches(account.id, statuses)
 
         statuses.each do |status|
-          next if filter_from_list?(status, account.id) || filter_from_home?(status, account.id, crutches)
+          next if filter_from_list?(status, account.id) || filter_from_home?(status, account.id, crutches, account.user&.filters_unknown?)
 
           add_to_feed(:list, list.id, status, list.account.user&.aggregates_reblogs?, !list.reblogs?)
         end
@@ -293,6 +295,7 @@ class FeedManager
     limit        = FeedManager::MAX_ITEMS / 2
     aggregate    = account.user&.aggregates_reblogs?
     no_reblogs   = account.user&.disables_home_reblogs?
+    no_unknown   = account.user&.filters_unknown?
     timeline_key = key(:home, account.id)
 
     account.statuses.limit(limit).each do |status|
@@ -314,7 +317,7 @@ class FeedManager
       crutches = build_crutches(account.id, statuses)
 
       statuses.each do |status|
-        next if filter_from_home?(status, account.id, crutches)
+        next if filter_from_home?(status, account.id, crutches, no_unknown)
 
         add_to_feed(:home, account.id, status, aggregate, no_reblogs, false)
       end
@@ -403,7 +406,7 @@ class FeedManager
   # @param [Integer] receiver_id
   # @param [Hash] crutches
   # @return [Boolean]
-  def filter_from_home?(status, receiver_id, crutches)
+  def filter_from_home?(status, receiver_id, crutches, followed_only = false)
     return false if receiver_id == status.account_id
     return true  if !status.published? || crutches[:hiding_thread][status.conversation_id]
     return true  if status.reply? && (status.in_reply_to_id.nil? || status.in_reply_to_account_id.nil?)
@@ -431,7 +434,7 @@ class FeedManager
       return !!should_filter
     elsif status.reblog? # ...it's a boost and...
       # ...you don't follow the OP and they're non-local or they're silenced...
-      should_filter = !(crutches[:local][status.reblog.account_id] || crutches[:following][status.reblog.account_id])
+      should_filter = followed_only && !crutches[:following][status.reblog.account_id]
 
       # ..or you're hiding boosts from them...
       should_filter ||= crutches[:hiding_reblogs][status.account_id]
@@ -561,7 +564,7 @@ class FeedManager
 
     if status.reblog?
       add_to_reblogs(account_id, status, aggregate_reblogs, stream) if timeline_type == :home
-      return false if skip_reblogs
+      return false if skip_reblogs || (timeline_type == :home && !status.reblog.local?)
     end
 
     if status.reblog? && (aggregate_reblogs.nil? || aggregate_reblogs)
@@ -666,7 +669,6 @@ class FeedManager
     crutches[:domain_blocking] = AccountDomainBlock.where(account_id: receiver_id, domain: statuses.map { |s| s.reblog&.account&.domain }.compact).pluck(:domain).each_with_object({}) { |domain, mapping| mapping[domain] = true }
     crutches[:blocked_by]      = Block.where(target_account_id: receiver_id, account_id: statuses.map { |s| s.reblog&.account_id }.compact).pluck(:account_id).each_with_object({}) { |id, mapping| mapping[id] = true }
     crutches[:hiding_thread]   = ConversationMute.where(account_id: receiver_id, conversation_id: statuses.map(&:conversation_id).compact).pluck(:conversation_id).each_with_object({}) { |id, mapping| mapping[id] = true }
-    crutches[:local]           = Account.local.where(id: participants, silenced_at: nil, suspended_at: nil).pluck(:id).each_with_object({}) { |id, mapping| mapping[id] = true }
 
     crutches
   end
diff --git a/app/lib/user_settings_decorator.rb b/app/lib/user_settings_decorator.rb
index e5bc7276c..8bed47835 100644
--- a/app/lib/user_settings_decorator.rb
+++ b/app/lib/user_settings_decorator.rb
@@ -60,6 +60,7 @@ class UserSettingsDecorator
     user.settings['boost_every']         = boost_every_preference if change?('setting_boost_every')
     user.settings['boost_jitter']        = boost_jitter_preference if change?('setting_boost_jitter')
     user.settings['boost_random']        = boost_random_preference if change?('setting_boost_random')
+    user.settings['filter_unknown']      = filter_unknown_preference if change?('setting_filter_unknown')
     user.settings['unpublish_on_delete'] = unpublish_on_delete_preference if change?('setting_unpublish_on_delete')
     user.settings['rss_disabled']        = rss_disabled_preference if change?('setting_rss_disabled')
     user.settings['no_boosts_home']      = no_boosts_home_preference if change?('setting_no_boosts_home')
@@ -229,6 +230,10 @@ class UserSettingsDecorator
     boolean_cast_setting 'setting_boost_random'
   end
 
+  def filter_unknown_preference
+    boolean_cast_setting 'setting_filter_unknown'
+  end
+
   def unpublish_on_delete_preference
     boolean_cast_setting 'setting_unpublish_on_delete'
   end
diff --git a/app/models/user.rb b/app/models/user.rb
index 12c1e9650..f9a0df46f 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -124,6 +124,7 @@ class User < ApplicationRecord
            :style_wide_media,
            :publish_in, :unpublish_in, :unpublish_delete, :boost_every, :boost_jitter,
            :boost_random, :unpublish_on_delete, :rss_disabled, :no_boosts_home,
+           :filter_unknown,
            to: :settings, prefix: :setting, allow_nil: false
 
   attr_reader :invite_code, :sign_in_token_attempt
@@ -266,6 +267,10 @@ class User < ApplicationRecord
     @disables_home_reblogs ||= settings.no_boosts_home
   end
 
+  def filters_unknown?
+    @filters_unknown ||= settings.filter_unknown
+  end
+
   # rubocop:disable Naming/MethodParameterName
   def token_for_app(a)
     return nil if a.nil? || a.owner != self
diff --git a/app/views/settings/preferences/filters/show.html.haml b/app/views/settings/preferences/filters/show.html.haml
index ae0993bc7..c30167cb5 100644
--- a/app/views/settings/preferences/filters/show.html.haml
+++ b/app/views/settings/preferences/filters/show.html.haml
@@ -12,6 +12,9 @@
   .fields-group
     = f.input :setting_no_boosts_home, as: :boolean, wrapper: :with_label
 
+  .fields-group
+    = f.input :setting_filter_unknown, as: :boolean, wrapper: :with_label
+
   %h4= t 'preferences.public_timelines'
 
   .fields-group