闭社主体 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.

33 lines
1.1 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. next_path = api_v1_follow_requests_url(pagination_params(max_id: results.last.id)) if results.size == DEFAULT_ACCOUNTS_LIMIT
  10. prev_path = api_v1_follow_requests_url(pagination_params(since_id: results.first.id)) unless results.empty?
  11. set_pagination_headers(next_path, prev_path)
  12. end
  13. def authorize
  14. AuthorizeFollowService.new.call(Account.find(params[:id]), current_account)
  15. render_empty
  16. end
  17. def reject
  18. RejectFollowService.new.call(Account.find(params[:id]), current_account)
  19. render_empty
  20. end
  21. private
  22. def pagination_params(core_params)
  23. params.permit(:limit).merge(core_params)
  24. end
  25. end