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.

59 lines
1.8 KiB

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