2020-09-07 05:02:04 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-01-07 03:40:55 -05:00
|
|
|
class PublicFeed
|
2020-09-07 05:02:04 -04:00
|
|
|
# @param [Account] account
|
|
|
|
# @param [Hash] options
|
|
|
|
# @option [Boolean] :with_replies
|
|
|
|
# @option [Boolean] :with_reblogs
|
|
|
|
# @option [Boolean] :local
|
|
|
|
# @option [Boolean] :remote
|
|
|
|
# @option [Boolean] :only_media
|
2020-09-08 10:01:55 -04:00
|
|
|
# @option [Boolean] :allow_local_only
|
2022-10-04 21:48:06 -04:00
|
|
|
# @option [String] :locale
|
2020-09-07 05:02:04 -04:00
|
|
|
def initialize(account, options = {})
|
|
|
|
@account = account
|
|
|
|
@options = options
|
|
|
|
end
|
|
|
|
|
|
|
|
# @param [Integer] limit
|
|
|
|
# @param [Integer] max_id
|
|
|
|
# @param [Integer] since_id
|
|
|
|
# @param [Integer] min_id
|
|
|
|
# @return [Array<Status>]
|
|
|
|
def get(limit, max_id = nil, since_id = nil, min_id = nil)
|
|
|
|
scope = public_scope
|
|
|
|
|
2020-09-08 10:01:55 -04:00
|
|
|
scope.merge!(without_local_only_scope) unless allow_local_only?
|
2020-09-07 05:02:04 -04:00
|
|
|
scope.merge!(without_replies_scope) unless with_replies?
|
|
|
|
scope.merge!(without_reblogs_scope) unless with_reblogs?
|
|
|
|
scope.merge!(local_only_scope) if local_only?
|
|
|
|
scope.merge!(remote_only_scope) if remote_only?
|
|
|
|
scope.merge!(account_filters_scope) if account?
|
|
|
|
scope.merge!(media_only_scope) if media_only?
|
2022-10-04 21:48:06 -04:00
|
|
|
scope.merge!(language_scope)
|
2020-09-07 05:02:04 -04:00
|
|
|
|
|
|
|
scope.cache_ids.to_a_paginated_by_id(limit, max_id: max_id, since_id: since_id, min_id: min_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-01-07 03:40:55 -05:00
|
|
|
attr_reader :account, :options
|
|
|
|
|
2020-09-08 10:01:55 -04:00
|
|
|
def allow_local_only?
|
2021-01-11 05:55:42 -05:00
|
|
|
local_account? && (local_only? || options[:allow_local_only])
|
2020-09-08 10:01:55 -04:00
|
|
|
end
|
|
|
|
|
2020-09-07 05:02:04 -04:00
|
|
|
def with_reblogs?
|
2021-01-07 03:40:55 -05:00
|
|
|
options[:with_reblogs]
|
2020-09-07 05:02:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def with_replies?
|
2021-01-07 03:40:55 -05:00
|
|
|
options[:with_replies]
|
2020-09-07 05:02:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def local_only?
|
2021-01-07 03:40:55 -05:00
|
|
|
options[:local]
|
2020-09-07 05:02:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def remote_only?
|
2021-01-07 03:40:55 -05:00
|
|
|
options[:remote]
|
2020-09-07 05:02:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def account?
|
2021-01-07 03:40:55 -05:00
|
|
|
account.present?
|
2020-09-07 05:02:04 -04:00
|
|
|
end
|
|
|
|
|
2020-09-08 10:01:55 -04:00
|
|
|
def local_account?
|
2021-01-11 05:55:42 -05:00
|
|
|
account&.local?
|
2020-09-08 10:01:55 -04:00
|
|
|
end
|
|
|
|
|
2020-09-07 05:02:04 -04:00
|
|
|
def media_only?
|
2021-01-07 03:40:55 -05:00
|
|
|
options[:only_media]
|
2020-09-07 05:02:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def public_scope
|
|
|
|
Status.with_public_visibility.joins(:account).merge(Account.without_suspended.without_silenced)
|
|
|
|
end
|
|
|
|
|
|
|
|
def local_only_scope
|
|
|
|
Status.local
|
|
|
|
end
|
|
|
|
|
|
|
|
def remote_only_scope
|
|
|
|
Status.remote
|
|
|
|
end
|
|
|
|
|
|
|
|
def without_replies_scope
|
|
|
|
Status.without_replies
|
|
|
|
end
|
|
|
|
|
|
|
|
def without_reblogs_scope
|
|
|
|
Status.without_reblogs
|
|
|
|
end
|
|
|
|
|
|
|
|
def media_only_scope
|
|
|
|
Status.joins(:media_attachments).group(:id)
|
|
|
|
end
|
|
|
|
|
2020-09-08 10:01:55 -04:00
|
|
|
def without_local_only_scope
|
|
|
|
Status.not_local_only
|
|
|
|
end
|
|
|
|
|
2022-10-04 21:48:06 -04:00
|
|
|
def language_scope
|
|
|
|
if account&.chosen_languages.present?
|
|
|
|
Status.where(language: account.chosen_languages)
|
|
|
|
elsif @options[:locale].present?
|
|
|
|
Status.where(language: @options[:locale])
|
|
|
|
else
|
|
|
|
Status.all
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-07 05:02:04 -04:00
|
|
|
def account_filters_scope
|
2021-01-07 03:40:55 -05:00
|
|
|
Status.not_excluded_by_account(account).tap do |scope|
|
|
|
|
scope.merge!(Status.not_domain_blocked_by_account(account)) unless local_only?
|
2020-09-07 05:02:04 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|