logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

follower_accounts_controller.rb (1552B)


  1. # frozen_string_literal: true
  2. class Api::V1::Accounts::FollowerAccountsController < Api::BaseController
  3. before_action -> { doorkeeper_authorize! :read }
  4. before_action :set_account
  5. after_action :insert_pagination_headers
  6. respond_to :json
  7. def index
  8. @accounts = load_accounts
  9. render json: @accounts, each_serializer: REST::AccountSerializer
  10. end
  11. private
  12. def set_account
  13. @account = Account.find(params[:account_id])
  14. end
  15. def load_accounts
  16. default_accounts.merge(paginated_follows).to_a
  17. end
  18. def default_accounts
  19. Account.includes(:active_relationships).references(:active_relationships)
  20. end
  21. def paginated_follows
  22. Follow.where(target_account: @account).paginate_by_max_id(
  23. limit_param(DEFAULT_ACCOUNTS_LIMIT),
  24. params[:max_id],
  25. params[:since_id]
  26. )
  27. end
  28. def insert_pagination_headers
  29. set_pagination_headers(next_path, prev_path)
  30. end
  31. def next_path
  32. if records_continue?
  33. api_v1_account_followers_url pagination_params(max_id: pagination_max_id)
  34. end
  35. end
  36. def prev_path
  37. unless @accounts.empty?
  38. api_v1_account_followers_url pagination_params(since_id: pagination_since_id)
  39. end
  40. end
  41. def pagination_max_id
  42. @accounts.last.active_relationships.first.id
  43. end
  44. def pagination_since_id
  45. @accounts.first.active_relationships.first.id
  46. end
  47. def records_continue?
  48. @accounts.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
  49. end
  50. def pagination_params(core_params)
  51. params.slice(:limit).permit(:limit).merge(core_params)
  52. end
  53. end