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 FollowingAccountsController < ApplicationController
  3. include AccountControllerConcern
  4. def index
  5. respond_to do |format|
  6. format.html do
  7. follows
  8. @relationships = AccountRelationshipsPresenter.new(follows.map(&:target_account_id), current_user.account_id) if user_signed_in?
  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 follows
  20. @follows ||= Follow.where(account: @account).recent.page(params[:page]).per(FOLLOW_PER_PAGE).preload(:target_account)
  21. end
  22. def page_url(page)
  23. account_following_index_url(@account, page: page) unless page.nil?
  24. end
  25. def collection_presenter
  26. if params[:page].present?
  27. ActivityPub::CollectionPresenter.new(
  28. id: account_following_index_url(@account, page: params.fetch(:page, 1)),
  29. type: :ordered,
  30. size: @account.following_count,
  31. items: follows.map { |f| ActivityPub::TagManager.instance.uri_for(f.target_account) },
  32. part_of: account_following_index_url(@account),
  33. next: page_url(follows.next_page),
  34. prev: page_url(follows.prev_page)
  35. )
  36. else
  37. ActivityPub::CollectionPresenter.new(
  38. id: account_following_index_url(@account),
  39. type: :ordered,
  40. size: @account.following_count,
  41. first: page_url(1)
  42. )
  43. end
  44. end
  45. end