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.

48 lines
1.3 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
  8. format.json do
  9. render json: collection_presenter,
  10. serializer: ActivityPub::CollectionSerializer,
  11. adapter: ActivityPub::Adapter,
  12. content_type: 'application/activity+json'
  13. end
  14. end
  15. end
  16. private
  17. def page_url(page)
  18. account_following_index_url(@account, page: page) unless page.nil?
  19. end
  20. def collection_presenter
  21. page = ActivityPub::CollectionPresenter.new(
  22. id: account_following_index_url(@account, page: params.fetch(:page, 1)),
  23. type: :ordered,
  24. size: @account.following_count,
  25. items: @follows.map { |f| ActivityPub::TagManager.instance.uri_for(f.target_account) },
  26. part_of: account_following_index_url(@account),
  27. next: page_url(@follows.next_page),
  28. prev: page_url(@follows.prev_page)
  29. )
  30. if params[:page].present?
  31. page
  32. else
  33. ActivityPub::CollectionPresenter.new(
  34. id: account_following_index_url(@account),
  35. type: :ordered,
  36. size: @account.following_count,
  37. first: page
  38. )
  39. end
  40. end
  41. end