The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

75 lines
2.1 KiB

  1. # frozen_string_literal: true
  2. class FollowerAccountsController < 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. skip_around_action :set_locale, if: -> { request.format == :json }
  8. skip_before_action :require_functional!
  9. def index
  10. respond_to do |format|
  11. format.html do
  12. expires_in 0, public: true unless user_signed_in?
  13. next if @account.user_hides_network?
  14. follows
  15. end
  16. format.json do
  17. raise Mastodon::NotPermittedError if page_requested? && @account.user_hides_network?
  18. expires_in(page_requested? ? 0 : 3.minutes, public: public_fetch_mode?)
  19. render json: collection_presenter,
  20. serializer: ActivityPub::CollectionSerializer,
  21. adapter: ActivityPub::Adapter,
  22. content_type: 'application/activity+json'
  23. end
  24. end
  25. end
  26. private
  27. def follows
  28. return @follows if defined?(@follows)
  29. scope = Follow.where(target_account: @account)
  30. scope = scope.where.not(account_id: current_account.excluded_from_timeline_account_ids) if user_signed_in?
  31. @follows = scope.recent.page(params[:page]).per(FOLLOW_PER_PAGE).preload(:account)
  32. end
  33. def page_requested?
  34. params[:page].present?
  35. end
  36. def page_url(page)
  37. account_followers_url(@account, page: page) unless page.nil?
  38. end
  39. def collection_presenter
  40. if page_requested?
  41. ActivityPub::CollectionPresenter.new(
  42. id: account_followers_url(@account, page: params.fetch(:page, 1)),
  43. type: :ordered,
  44. size: @account.followers_count,
  45. items: follows.map { |f| ActivityPub::TagManager.instance.uri_for(f.account) },
  46. part_of: account_followers_url(@account),
  47. next: page_url(follows.next_page),
  48. prev: page_url(follows.prev_page)
  49. )
  50. else
  51. ActivityPub::CollectionPresenter.new(
  52. id: account_followers_url(@account),
  53. type: :ordered,
  54. size: @account.followers_count,
  55. first: page_url(1)
  56. )
  57. end
  58. end
  59. end