The code powering m.abunchtell.com https://m.abunchtell.com
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

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