1 # frozen_string_literal: true
3 class FollowerAccountsController
< ApplicationController
4 include AccountControllerConcern
5 include SignatureVerification
7 before_action
:require_signature!
, if: -> { request
.format
== :json && authorized_fetch_mode
? }
8 before_action
:set_cache_headers
10 skip_around_action
:set_locale, if: -> { request
.format
== :json }
11 skip_before_action
:require_functional!
14 respond_to
do |format
|
16 expires_in
0, public
: true unless user_signed_in
?
18 next if @account.user_hides_network
?
24 raise Mastodon
::NotPermittedError if page_requested
? && @account.user_hides_network
?
26 expires_in(page_requested
? ? 0 : 3.minutes
, public
: public_fetch_mode
?)
28 render json
: collection_presenter
,
29 serializer
: ActivityPub
::CollectionSerializer,
30 adapter
: ActivityPub
::Adapter,
31 content_type
: 'application/activity+json
',
32 fields: restrict_fields_to
40 return @follows if defined?(@follows)
42 scope = Follow.where(target_account: @account)
43 scope = scope.where.not(account_id: current_account.excluded_from_timeline_account_ids) if user_signed_in?
44 @follows = scope.recent.page(params[:page]).per(FOLLOW_PER_PAGE).preload(:account)
48 params[:page].present?
52 account_followers_url(@account, page: page) unless page.nil?
55 def collection_presenter
57 ActivityPub::CollectionPresenter.new(
58 id: account_followers_url(@account, page: params.fetch(:page, 1)),
60 size: @account.followers_count,
61 items: follows.map { |f| ActivityPub::TagManager.instance.uri_for(f.account) },
62 part_of: account_followers_url(@account),
63 next: page_url(follows.next_page),
64 prev: page_url(follows.prev_page)
67 ActivityPub::CollectionPresenter.new(
68 id: account_followers_url(@account),
70 size: @account.followers_count,
76 def restrict_fields_to
77 if page_requested? || !@account.user_hides_network
?
80 %i(id type totalItems
)