The code powering m.abunchtell.com https://m.abunchtell.com
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

71 строка
2.0 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. @follows ||= Follow.where(target_account: @account).recent.page(params[:page]).per(FOLLOW_PER_PAGE).preload(:account)
  29. end
  30. def page_requested?
  31. params[:page].present?
  32. end
  33. def page_url(page)
  34. account_followers_url(@account, page: page) unless page.nil?
  35. end
  36. def collection_presenter
  37. if page_requested?
  38. ActivityPub::CollectionPresenter.new(
  39. id: account_followers_url(@account, page: params.fetch(:page, 1)),
  40. type: :ordered,
  41. size: @account.followers_count,
  42. items: follows.map { |f| ActivityPub::TagManager.instance.uri_for(f.account) },
  43. part_of: account_followers_url(@account),
  44. next: page_url(follows.next_page),
  45. prev: page_url(follows.prev_page)
  46. )
  47. else
  48. ActivityPub::CollectionPresenter.new(
  49. id: account_followers_url(@account),
  50. type: :ordered,
  51. size: @account.followers_count,
  52. first: page_url(1)
  53. )
  54. end
  55. end
  56. end