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.

54 lines
1.5 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. follows
  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 follows
  21. @follows ||= Follow.where(target_account: @account).recent.page(params[:page]).per(FOLLOW_PER_PAGE).preload(:account)
  22. end
  23. def page_url(page)
  24. account_followers_url(@account, page: page) unless page.nil?
  25. end
  26. def collection_presenter
  27. if params[:page].present?
  28. ActivityPub::CollectionPresenter.new(
  29. id: account_followers_url(@account, page: params.fetch(:page, 1)),
  30. type: :ordered,
  31. size: @account.followers_count,
  32. items: follows.map { |f| ActivityPub::TagManager.instance.uri_for(f.account) },
  33. part_of: account_followers_url(@account),
  34. next: page_url(follows.next_page),
  35. prev: page_url(follows.prev_page)
  36. )
  37. else
  38. ActivityPub::CollectionPresenter.new(
  39. id: account_followers_url(@account),
  40. type: :ordered,
  41. size: @account.followers_count,
  42. first: page_url(1)
  43. )
  44. end
  45. end
  46. end