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.

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