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.
 
 
 
 

65 lines
1.9 KiB

  1. # frozen_string_literal: true
  2. class ActivityPub::OutboxesController < ActivityPub::BaseController
  3. LIMIT = 20
  4. include SignatureVerification
  5. include AccountOwnedConcern
  6. before_action :require_signature!, if: :authorized_fetch_mode?
  7. before_action :set_statuses
  8. before_action :set_cache_headers
  9. def show
  10. expires_in(page_requested? ? 0 : 3.minutes, public: public_fetch_mode?)
  11. render json: outbox_presenter, serializer: ActivityPub::OutboxSerializer, adapter: ActivityPub::Adapter, content_type: 'application/activity+json'
  12. end
  13. private
  14. def outbox_presenter
  15. if page_requested?
  16. ActivityPub::CollectionPresenter.new(
  17. id: account_outbox_url(@account, page_params),
  18. type: :ordered,
  19. part_of: account_outbox_url(@account),
  20. prev: prev_page,
  21. next: next_page,
  22. items: @statuses
  23. )
  24. else
  25. ActivityPub::CollectionPresenter.new(
  26. id: account_outbox_url(@account),
  27. type: :ordered,
  28. size: @account.statuses_count,
  29. first: account_outbox_url(@account, page: true),
  30. last: account_outbox_url(@account, page: true, min_id: 0)
  31. )
  32. end
  33. end
  34. def next_page
  35. account_outbox_url(@account, page: true, max_id: @statuses.last.id) if @statuses.size == LIMIT
  36. end
  37. def prev_page
  38. account_outbox_url(@account, page: true, min_id: @statuses.first.id) unless @statuses.empty?
  39. end
  40. def set_statuses
  41. return unless page_requested?
  42. @statuses = @account.statuses.permitted_for(@account, signed_request_account)
  43. @statuses = params[:min_id].present? ? @statuses.paginate_by_min_id(LIMIT, params[:min_id]).reverse : @statuses.paginate_by_max_id(LIMIT, params[:max_id])
  44. @statuses = cache_collection(@statuses, Status)
  45. end
  46. def page_requested?
  47. params[:page] == 'true'
  48. end
  49. def page_params
  50. { page: true, max_id: params[:max_id], min_id: params[:min_id] }.compact
  51. end
  52. end