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. if params[:page].present?
  30. ActivityPub::CollectionPresenter.new(
  31. id: account_followers_url(@account, page: params.fetch(:page, 1)),
  32. type: :ordered,
  33. size: @account.followers_count,
  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. )
  39. else
  40. ActivityPub::CollectionPresenter.new(
  41. id: account_followers_url(@account),
  42. type: :ordered,
  43. size: @account.followers_count,
  44. first: page_url(1)
  45. )
  46. end
  47. end
  48. end