From eb4358efb766b383ae40304c23d30727d405ccc5 Mon Sep 17 00:00:00 2001 From: Fire Demon Date: Fri, 9 Oct 2020 21:48:14 -0500 Subject: Merge "filter boosts from unfollowed" behavior directly into feed manager but keep local --- app/controllers/settings/preferences_controller.rb | 1 - app/lib/feed_manager.rb | 36 ++++++---------------- app/lib/user_settings_decorator.rb | 5 --- app/models/user.rb | 3 +- .../settings/preferences/filters/show.html.haml | 3 -- 5 files changed, 11 insertions(+), 37 deletions(-) (limited to 'app') diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb index f3fbd9654..9cb05ed7e 100644 --- a/app/controllers/settings/preferences_controller.rb +++ b/app/controllers/settings/preferences_controller.rb @@ -72,7 +72,6 @@ class Settings::PreferencesController < Settings::BaseController :setting_boost_every, :setting_boost_jitter, :setting_boost_random, - :setting_filter_from_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 1b11e463f..264aec0a3 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_options_for(receiver.id)) + filter_from_home?(status, receiver.id, build_crutches(receiver.id, [status])) when :list - filter_from_list?(status, receiver) || filter_from_home?(status, receiver.account_id, build_crutches(receiver.account_id, [status]), filter_options_for(receiver.id)) + filter_from_list?(status, receiver) || filter_from_home?(status, receiver.account_id, build_crutches(receiver.account_id, [status])) when :mentions filter_from_mentions?(status, receiver.id) when :direct @@ -157,10 +157,9 @@ class FeedManager statuses = query.to_a crutches = build_crutches(into_account.id, statuses) - filter_options = filter_options_for(into_account.id) statuses.each do |status| - next if filter_from_home?(status, into_account.id, crutches, filter_options) + next if filter_from_home?(status, into_account.id, crutches) add_to_feed(:home, into_account.id, status, aggregate, no_reblogs) end @@ -185,10 +184,9 @@ class FeedManager statuses = query.to_a crutches = build_crutches(list.account_id, statuses) - filter_options = filter_options_for(list.account.id) statuses.each do |status| - next if filter_from_home?(status, list.account_id, crutches, filter_options) || filter_from_list?(status, list) + next if filter_from_home?(status, list.account_id, crutches) || filter_from_list?(status, list) add_to_feed(:list, list.id, status, aggregate, no_reblogs) end @@ -262,7 +260,6 @@ class FeedManager account.owned_lists.includes(:accounts) do |list| timeline_key = key(:list, list.id) - filter_options = filter_options_for(account.id) list.accounts.includes(:account_stat).find_each do |target_account| if redis.zcard(timeline_key) >= limit @@ -279,7 +276,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, filter_options) + next if filter_from_list?(status, account.id) || filter_from_home?(status, account.id, crutches) add_to_feed(:list, list.id, status, list.account.user&.aggregates_reblogs?, !list.reblogs?) end @@ -315,10 +312,9 @@ class FeedManager statuses = target_account.statuses.published.where(visibility: [:public, :unlisted, :private]).includes(:mentions, :preloadable_poll, reblog: [:account, :mentions]).limit(limit) crutches = build_crutches(account.id, statuses) - filter_options = filter_options_for(account.id) statuses.each do |status| - next if filter_from_home?(status, account.id, crutches, filter_options) + next if filter_from_home?(status, account.id, crutches) add_to_feed(:home, account.id, status, aggregate, no_reblogs, false) end @@ -406,9 +402,8 @@ class FeedManager # @param [Status] status # @param [Integer] receiver_id # @param [Hash] crutches - # @param [Hash] filter_options # @return [Boolean] - def filter_from_home?(status, receiver_id, crutches, filter_options) + def filter_from_home?(status, receiver_id, crutches) 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?) @@ -435,10 +430,8 @@ class FeedManager return !!should_filter elsif status.reblog? # ...it's a boost and... - # ...you don't follow the author if: - # - you're filtering boosts of folks you don't follow - # - they're silenced on this server - should_filter = (filter_options[:from_unknown] || status.reblog.account.silenced?) && !crutches[:following][status.reblog.account_id] + # ...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]) # ..or you're hiding boosts from them... should_filter ||= crutches[:hiding_reblogs][status.account_id] @@ -653,16 +646,6 @@ class FeedManager redis.zrem(timeline_key, status.id) end - def filter_options_for(receiver_id) - Rails.cache.fetch("filter_settings:#{receiver_id}", expires_in: 1.month) do - return {} if (settings = User.find_by(account_id: receiver_id)&.settings).blank? - - { - from_unknown: settings.filter_from_unknown, - } - end - end - # Pre-fetch various objects and relationships for given statuses that # are going to be checked by the filtering methods # @param [Integer] receiver_id @@ -683,6 +666,7 @@ 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 e863550da..e5bc7276c 100644 --- a/app/lib/user_settings_decorator.rb +++ b/app/lib/user_settings_decorator.rb @@ -60,7 +60,6 @@ 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_from_unknown'] = filter_from_unknown_preference if change?('setting_filter_from_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') @@ -230,10 +229,6 @@ class UserSettingsDecorator boolean_cast_setting 'setting_boost_random' end - def filter_from_unknown_preference - boolean_cast_setting 'setting_filter_from_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 07fb9e1bb..12c1e9650 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -123,8 +123,7 @@ class User < ApplicationRecord :style_css_profile_errors, :style_css_webapp, :style_css_webapp_errors, :style_wide_media, :publish_in, :unpublish_in, :unpublish_delete, :boost_every, :boost_jitter, - :boost_random, :filter_from_unknown, :unpublish_on_delete, - :rss_disabled, :no_boosts_home, + :boost_random, :unpublish_on_delete, :rss_disabled, :no_boosts_home, to: :settings, prefix: :setting, allow_nil: false attr_reader :invite_code, :sign_in_token_attempt diff --git a/app/views/settings/preferences/filters/show.html.haml b/app/views/settings/preferences/filters/show.html.haml index 5794859b6..ae0993bc7 100644 --- a/app/views/settings/preferences/filters/show.html.haml +++ b/app/views/settings/preferences/filters/show.html.haml @@ -12,9 +12,6 @@ .fields-group = f.input :setting_no_boosts_home, as: :boolean, wrapper: :with_label - .fields-group - = f.input :setting_filter_from_unknown, as: :boolean, wrapper: :with_label - %h4= t 'preferences.public_timelines' .fields-group -- cgit