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.

35 lines
1.2 KiB

  1. # frozen_string_literal: true
  2. class Api::V1::FollowRequestsController < ApiController
  3. before_action -> { doorkeeper_authorize! :follow }
  4. before_action :require_user!
  5. def index
  6. @accounts = Account.includes(:follow_requests)
  7. .references(:follow_requests)
  8. .merge(FollowRequest.where(target_account: current_account)
  9. .paginate_by_max_id(DEFAULT_ACCOUNTS_LIMIT, params[:max_id], params[:since_id]))
  10. .to_a
  11. next_path = api_v1_follow_requests_url(pagination_params(max_id: @accounts.last.follow_requests.last.id)) if @accounts.size == DEFAULT_ACCOUNTS_LIMIT
  12. prev_path = api_v1_follow_requests_url(pagination_params(since_id: @accounts.first.follow_requests.first.id)) unless @accounts.empty?
  13. set_pagination_headers(next_path, prev_path)
  14. end
  15. def authorize
  16. AuthorizeFollowService.new.call(Account.find(params[:id]), current_account)
  17. render_empty
  18. end
  19. def reject
  20. RejectFollowService.new.call(Account.find(params[:id]), current_account)
  21. render_empty
  22. end
  23. private
  24. def pagination_params(core_params)
  25. params.permit(:limit).merge(core_params)
  26. end
  27. end