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.

69 lines
2.1 KiB

  1. # frozen_string_literal: true
  2. class FollowerAccountsController < ApplicationController
  3. include AccountControllerConcern
  4. include SignatureVerification
  5. before_action :require_signature!, if: -> { request.format == :json && authorized_fetch_mode? }
  6. before_action :set_cache_headers
  7. def index
  8. respond_to do |format|
  9. format.html do
  10. use_pack 'public'
  11. expires_in 0, public: true unless user_signed_in?
  12. next if @account.user_hides_network?
  13. follows
  14. @relationships = AccountRelationshipsPresenter.new(follows.map(&:account_id), current_user.account_id) if user_signed_in?
  15. end
  16. format.json do
  17. raise Mastodon::NotPermittedError if page_requested? && @account.user_hides_network?
  18. expires_in(page_requested? ? 0 : 3.minutes, public: public_fetch_mode?)
  19. render json: collection_presenter,
  20. serializer: ActivityPub::CollectionSerializer,
  21. adapter: ActivityPub::Adapter,
  22. content_type: 'application/activity+json'
  23. end
  24. end
  25. end
  26. private
  27. def follows
  28. @follows ||= Follow.where(target_account: @account).recent.page(params[:page]).per(FOLLOW_PER_PAGE).preload(:account)
  29. end
  30. def page_requested?
  31. params[:page].present?
  32. end
  33. def page_url(page)
  34. account_followers_url(@account, page: page) unless page.nil?
  35. end
  36. def collection_presenter
  37. options = { type: :ordered }
  38. options[:size] = @account.followers_count unless Setting.hide_followers_count || @account.user&.setting_hide_followers_count
  39. if page_requested?
  40. ActivityPub::CollectionPresenter.new(
  41. id: account_followers_url(@account, page: params.fetch(:page, 1)),
  42. items: follows.map { |f| ActivityPub::TagManager.instance.uri_for(f.account) },
  43. part_of: account_followers_url(@account),
  44. next: page_url(follows.next_page),
  45. prev: page_url(follows.prev_page),
  46. **options
  47. )
  48. else
  49. ActivityPub::CollectionPresenter.new(
  50. id: account_followers_url(@account),
  51. first: page_url(1),
  52. **options
  53. )
  54. end
  55. end
  56. end