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.

63 lines
1.9 KiB

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