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.

68 lines
2.0 KiB

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