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.

52 lines
1.5 KiB

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