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.
 
 
 
 

72 rivejä
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. @relationships = AccountRelationshipsPresenter.new(follows.map(&:account_id), current_user.account_id) if user_signed_in?
  16. end
  17. format.json do
  18. raise Mastodon::NotPermittedError if page_requested? && @account.user_hides_network?
  19. expires_in(page_requested? ? 0 : 3.minutes, public: public_fetch_mode?)
  20. render json: collection_presenter,
  21. serializer: ActivityPub::CollectionSerializer,
  22. adapter: ActivityPub::Adapter,
  23. content_type: 'application/activity+json'
  24. end
  25. end
  26. end
  27. private
  28. def follows
  29. @follows ||= Follow.where(target_account: @account).recent.page(params[:page]).per(FOLLOW_PER_PAGE).preload(:account)
  30. end
  31. def page_requested?
  32. params[:page].present?
  33. end
  34. def page_url(page)
  35. account_followers_url(@account, page: page) unless page.nil?
  36. end
  37. def collection_presenter
  38. if page_requested?
  39. ActivityPub::CollectionPresenter.new(
  40. id: account_followers_url(@account, page: params.fetch(:page, 1)),
  41. type: :ordered,
  42. size: @account.followers_count,
  43. items: follows.map { |f| ActivityPub::TagManager.instance.uri_for(f.account) },
  44. part_of: account_followers_url(@account),
  45. next: page_url(follows.next_page),
  46. prev: page_url(follows.prev_page)
  47. )
  48. else
  49. ActivityPub::CollectionPresenter.new(
  50. id: account_followers_url(@account),
  51. type: :ordered,
  52. size: @account.followers_count,
  53. first: page_url(1)
  54. )
  55. end
  56. end
  57. end