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.

29 lines
1.0 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. results = FollowRequest.where(target_account: current_account).paginate_by_max_id(DEFAULT_ACCOUNTS_LIMIT, params[:max_id], params[:since_id])
  7. accounts = Account.where(id: results.map(&:account_id)).map { |a| [a.id, a] }.to_h
  8. @accounts = results.map { |f| accounts[f.account_id] }
  9. set_account_counters_maps(@accounts)
  10. next_path = api_v1_follow_requests_url(max_id: results.last.id) if results.size == DEFAULT_ACCOUNTS_LIMIT
  11. prev_path = api_v1_follow_requests_url(since_id: results.first.id) unless results.empty?
  12. set_pagination_headers(next_path, prev_path)
  13. end
  14. def authorize
  15. FollowRequest.find_by!(account_id: params[:id], target_account: current_account).authorize!
  16. render_empty
  17. end
  18. def reject
  19. FollowRequest.find_by!(account_id: params[:id], target_account: current_account).reject!
  20. render_empty
  21. end
  22. end