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.

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