The code powering m.abunchtell.com https://m.abunchtell.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

31 lines
1.1 KiB

  1. # frozen_string_literal: true
  2. class Api::V1::DirectoriesController < Api::BaseController
  3. before_action :require_enabled!
  4. before_action :set_accounts
  5. def show
  6. render json: @accounts, each_serializer: REST::AccountSerializer
  7. end
  8. private
  9. def require_enabled!
  10. return not_found unless Setting.profile_directory
  11. end
  12. def set_accounts
  13. @accounts = accounts_scope.offset(params[:offset]).limit(limit_param(DEFAULT_ACCOUNTS_LIMIT))
  14. end
  15. def accounts_scope
  16. Account.discoverable.tap do |scope|
  17. scope.merge!(Account.local) if truthy_param?(:local)
  18. scope.merge!(Account.by_recent_status) if params[:order].blank? || params[:order] == 'active'
  19. scope.merge!(Account.order(id: :desc)) if params[:order] == 'new'
  20. scope.merge!(Account.not_excluded_by_account(current_account)) if current_account
  21. scope.merge!(Account.not_domain_blocked_by_account(current_account)) if current_account && !truthy_param?(:local)
  22. end
  23. end
  24. end