From e9cf46b4bc928c19011f16214bf127d89ea338c2 Mon Sep 17 00:00:00 2001 From: Fosco Marotto Date: Thu, 21 Jan 2021 18:05:24 -0500 Subject: [PATCH] Reverting home timeline changes --- .../api/v1/timelines/explore_controller.rb | 7 ++-- .../timelines/group_collection_controller.rb | 6 ++-- .../api/v1/timelines/group_controller.rb | 2 +- app/lib/feed_manager.rb | 34 +++++++++---------- app/lib/sorting_query_builder.rb | 6 +--- app/models/home_feed.rb | 2 -- app/models/status.rb | 5 +-- 7 files changed, 26 insertions(+), 36 deletions(-) diff --git a/app/controllers/api/v1/timelines/explore_controller.rb b/app/controllers/api/v1/timelines/explore_controller.rb index 5a1586bc..fcf69c9a 100644 --- a/app/controllers/api/v1/timelines/explore_controller.rb +++ b/app/controllers/api/v1/timelines/explore_controller.rb @@ -44,10 +44,9 @@ class Api::V1::Timelines::ExploreController < Api::BaseController def explore_statuses if current_account - SortingQueryBuilder.new.call(@sort_type, nil, params[:page], current_account) - .reject {|status| - FeedManager.instance.filter?(:home, status, current_account.id) - } + SortingQueryBuilder.new.call(@sort_type, nil, params[:page]).reject {|status| + FeedManager.instance.filter?(:home, status, current_account.id) + } else page = [params[:page].to_i.abs, MIN_UNAUTHENTICATED_PAGES].min SortingQueryBuilder.new.call(@sort_type, nil, page) diff --git a/app/controllers/api/v1/timelines/group_collection_controller.rb b/app/controllers/api/v1/timelines/group_collection_controller.rb index 06369e25..22b61003 100644 --- a/app/controllers/api/v1/timelines/group_collection_controller.rb +++ b/app/controllers/api/v1/timelines/group_collection_controller.rb @@ -43,7 +43,7 @@ class Api::V1::Timelines::GroupCollectionController < Api::BaseController 'top_yearly', 'top_all_time', ].include? params[:sort_by] - + if @collection_type === 'featured' && (@sort_type == 'newest' || @sort_type == 'recent') @sort_type = 'hot' end @@ -66,9 +66,9 @@ class Api::V1::Timelines::GroupCollectionController < Api::BaseController elsif @collection_type == 'member' && !current_account.nil? @groupIds = current_account.groups.pluck(:id) end - + if current_account - SortingQueryBuilder.new.call(@sort_type, @groupIds, params[:page], current_account).reject {|status| + SortingQueryBuilder.new.call(@sort_type, @groupIds, params[:page]).reject {|status| FeedManager.instance.filter?(:home, status, current_account.id) } else diff --git a/app/controllers/api/v1/timelines/group_controller.rb b/app/controllers/api/v1/timelines/group_controller.rb index b1a87174..4bf9290b 100644 --- a/app/controllers/api/v1/timelines/group_controller.rb +++ b/app/controllers/api/v1/timelines/group_controller.rb @@ -51,7 +51,7 @@ class Api::V1::Timelines::GroupController < Api::BaseController def group_statuses if current_account - SortingQueryBuilder.new.call(@sort_type, @group, params[:page], current_account).reject {|status| + SortingQueryBuilder.new.call(@sort_type, @group, params[:page]).reject {|status| FeedManager.instance.filter?(:home, status, current_account.id) } else diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb index f008314d..3046bb4f 100644 --- a/app/lib/feed_manager.rb +++ b/app/lib/feed_manager.rb @@ -88,28 +88,28 @@ 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 status.reply? && (status.in_reply_to_id.nil? || status.in_reply_to_account_id.nil?) return true if phrase_filtered?(status, receiver_id, :home) - # check_for_blocks = status.active_mentions.pluck(:account_id) - # check_for_blocks.concat([status.account_id]) + check_for_blocks = status.active_mentions.pluck(:account_id) + check_for_blocks.concat([status.account_id]) - # if status.reblog? - # check_for_blocks.concat([status.reblog.account_id]) - # check_for_blocks.concat(status.reblog.active_mentions.pluck(:account_id)) - # end + if status.reblog? + check_for_blocks.concat([status.reblog.account_id]) + check_for_blocks.concat(status.reblog.active_mentions.pluck(:account_id)) + end - # return true if blocks_or_mutes?(receiver_id, check_for_blocks, :home) + 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 - # 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 - # return should_filter - #end + 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 + 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 + return should_filter + end return false if status.group_id diff --git a/app/lib/sorting_query_builder.rb b/app/lib/sorting_query_builder.rb index f6701a9e..1e323577 100644 --- a/app/lib/sorting_query_builder.rb +++ b/app/lib/sorting_query_builder.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class SortingQueryBuilder < BaseService - def call(sort_type, group = nil, page = 1, account = nil) + def call(sort_type, group = nil, page = 1) limit = 20 min_likes = 5 @@ -44,8 +44,6 @@ class SortingQueryBuilder < BaseService query = query.with_public_visibility if group.nil? query = query.where('statuses.created_at > ?', date_limit) query = query.where(group: group) unless group.nil? - query = query.excluding_blocked_reblogs(account) unless account.nil? - query = query.not_excluded_by_account(account) unless account.nil? query = query.page(page.to_i) query = query.per(limit) return query @@ -57,8 +55,6 @@ class SortingQueryBuilder < BaseService query = query.where('status_stats.reblogs_count > ?', min_reblogs) unless sort_type == 'recent' query = query.where('status_stats.favourites_count > ?', min_likes) unless sort_type == 'recent' query = query.joins(:status) - query = query.excluding_blocked_reblogs(account) unless account.nil? - query = query.not_excluded_by_account(account) unless account.nil? query = query.where('statuses.reblog_of_id IS NULL') query = query.where('statuses.in_reply_to_id IS NULL') query = query.where('statuses.group_id': group) unless group.nil? diff --git a/app/models/home_feed.rb b/app/models/home_feed.rb index 00e91664..595e5a52 100644 --- a/app/models/home_feed.rb +++ b/app/models/home_feed.rb @@ -20,8 +20,6 @@ class HomeFeed < Feed def from_database(limit, max_id, since_id, min_id) Status.as_home_timeline(@account) .paginate_by_id(limit, max_id: max_id, since_id: since_id, min_id: min_id) - .excluding_blocked_reblogs(@account) - .not_excluded_by_account(@account) .reject { |status| FeedManager.instance.filter?(:home, status, @account.id) } end end diff --git a/app/models/status.rb b/app/models/status.rb index 430815b1..195e600f 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -101,9 +101,6 @@ class Status < ApplicationRecord scope :tagged_with, ->(tag) { joins(:statuses_tags).where(statuses_tags: { tag_id: tag }) } scope :excluding_silenced_accounts, -> { left_outer_joins(:account).where(accounts: { silenced_at: nil }) } scope :including_silenced_accounts, -> { left_outer_joins(:account).where.not(accounts: { silenced_at: nil }) } - - scope :excluding_blocked_reblogs, ->(account) { left_outer_joins(:reblog).where.not(account_id: account.excluded_from_timeline_account_ids) } - scope :popular_accounts, -> { left_outer_joins(:account).where('accounts.is_verified=true OR accounts.is_pro=true AND accounts.locked=false') } scope :not_excluded_by_account, ->(account) { where.not(account_id: account.excluded_from_timeline_account_ids) } scope :not_domain_blocked_by_account, ->(account) { account.excluded_from_timeline_domains.blank? ? left_outer_joins(:account) : left_outer_joins(:account).where('accounts.domain IS NULL OR accounts.domain NOT IN (?)', account.excluded_from_timeline_domains) } @@ -293,7 +290,7 @@ class Status < ApplicationRecord end def as_home_timeline(account) - query = where('statuses.created_at > ?', 3.days.ago) + query = where('created_at > ?', 3.days.ago) query.where(account: [account] + account.following).without_replies end