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.

63 lines
1.8 KiB

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