闭社主体 forked from https://github.com/tootsuite/mastodon
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.

27 lines
960 B

  1. # frozen_string_literal: true
  2. class Api::V1::BlocksController < ApiController
  3. before_action -> { doorkeeper_authorize! :follow }
  4. before_action :require_user!
  5. respond_to :json
  6. def index
  7. @accounts = Account.includes(:blocked_by)
  8. .references(:blocked_by)
  9. .merge(Block.where(account: current_account)
  10. .paginate_by_max_id(limit_param(DEFAULT_ACCOUNTS_LIMIT), params[:max_id], params[:since_id]))
  11. .to_a
  12. next_path = api_v1_blocks_url(pagination_params(max_id: @accounts.last.blocked_by_ids.last)) if @accounts.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
  13. prev_path = api_v1_blocks_url(pagination_params(since_id: @accounts.first.blocked_by_ids.first)) unless @accounts.empty?
  14. set_pagination_headers(next_path, prev_path)
  15. end
  16. private
  17. def pagination_params(core_params)
  18. params.permit(:limit).merge(core_params)
  19. end
  20. end