2019-08-30 08:14:36 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Api::V1::DirectoriesController < Api::BaseController
|
|
|
|
before_action :require_enabled!
|
|
|
|
before_action :set_accounts
|
|
|
|
|
|
|
|
def show
|
2023-04-25 23:41:34 +10:00
|
|
|
cache_if_unauthenticated!
|
2019-08-30 08:14:36 +10:00
|
|
|
render json: @accounts, each_serializer: REST::AccountSerializer
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def require_enabled!
|
|
|
|
return not_found unless Setting.profile_directory
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_accounts
|
2023-09-09 01:01:02 +10:00
|
|
|
with_read_replica do
|
|
|
|
@accounts = accounts_scope.offset(params[:offset]).limit(limit_param(DEFAULT_ACCOUNTS_LIMIT))
|
|
|
|
end
|
2019-08-30 08:14:36 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
def accounts_scope
|
|
|
|
Account.discoverable.tap do |scope|
|
2023-07-02 05:48:16 +10:00
|
|
|
scope.merge!(account_order_scope)
|
|
|
|
scope.merge!(local_account_scope) if local_accounts?
|
|
|
|
scope.merge!(account_exclusion_scope) if current_account
|
|
|
|
scope.merge!(account_domain_block_scope) if current_account && !local_accounts?
|
2019-08-30 08:14:36 +10:00
|
|
|
end
|
|
|
|
end
|
2023-07-02 05:48:16 +10:00
|
|
|
|
|
|
|
def local_accounts?
|
|
|
|
truthy_param?(:local)
|
|
|
|
end
|
|
|
|
|
|
|
|
def account_order_scope
|
|
|
|
case params[:order]
|
|
|
|
when 'new'
|
|
|
|
Account.order(id: :desc)
|
|
|
|
when 'active', nil
|
|
|
|
Account.by_recent_status
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def local_account_scope
|
|
|
|
Account.local
|
|
|
|
end
|
|
|
|
|
|
|
|
def account_exclusion_scope
|
|
|
|
Account.not_excluded_by_account(current_account)
|
|
|
|
end
|
|
|
|
|
|
|
|
def account_domain_block_scope
|
|
|
|
Account.not_domain_blocked_by_account(current_account)
|
|
|
|
end
|
2019-08-30 08:14:36 +10:00
|
|
|
end
|