The code powering m.abunchtell.com https://m.abunchtell.com
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

72 satır
2.1 KiB

  1. # frozen_string_literal: true
  2. class ActivityPub::RepliesController < ActivityPub::BaseController
  3. include SignatureAuthentication
  4. include Authorization
  5. include AccountOwnedConcern
  6. DESCENDANTS_LIMIT = 60
  7. before_action :require_signature!, if: :authorized_fetch_mode?
  8. before_action :set_status
  9. before_action :set_cache_headers
  10. before_action :set_replies
  11. def index
  12. expires_in 0, public: public_fetch_mode?
  13. render json: replies_collection_presenter, serializer: ActivityPub::CollectionSerializer, adapter: ActivityPub::Adapter, content_type: 'application/activity+json', skip_activities: true
  14. end
  15. private
  16. def set_status
  17. @status = @account.statuses.find(params[:status_id])
  18. authorize @status, :show?
  19. rescue Mastodon::NotPermittedError
  20. raise ActiveRecord::RecordNotFound
  21. end
  22. def set_replies
  23. @replies = page_params[:only_other_accounts] ? Status.where.not(account_id: @account.id) : @account.statuses
  24. @replies = @replies.where(in_reply_to_id: @status.id, visibility: [:public, :unlisted])
  25. @replies = @replies.paginate_by_min_id(DESCENDANTS_LIMIT, params[:min_id])
  26. end
  27. def replies_collection_presenter
  28. page = ActivityPub::CollectionPresenter.new(
  29. id: account_status_replies_url(@account, @status, page_params),
  30. type: :unordered,
  31. part_of: account_status_replies_url(@account, @status),
  32. next: next_page,
  33. items: @replies.map { |status| status.local ? status : status.uri }
  34. )
  35. return page if page_requested?
  36. ActivityPub::CollectionPresenter.new(
  37. id: account_status_replies_url(@account, @status),
  38. type: :unordered,
  39. first: page
  40. )
  41. end
  42. def page_requested?
  43. params[:page] == 'true'
  44. end
  45. def next_page
  46. only_other_accounts = !(@replies&.last&.account_id == @account.id && @replies.size == DESCENDANTS_LIMIT)
  47. account_status_replies_url(
  48. @account,
  49. @status,
  50. page: true,
  51. min_id: only_other_accounts && !page_params[:only_other_accounts] ? nil : @replies&.last&.id,
  52. only_other_accounts: only_other_accounts
  53. )
  54. end
  55. def page_params
  56. params_slice(:only_other_accounts, :min_id).merge(page: true)
  57. end
  58. end