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.

50 lines
1.4 KiB

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