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.

41 lines
1.1 KiB

  1. # frozen_string_literal: true
  2. class Api::Activitypub::OutboxController < ApiController
  3. before_action :set_account
  4. respond_to :activitystreams2
  5. def show
  6. headers['Access-Control-Allow-Origin'] = '*'
  7. @statuses = Status.as_outbox_timeline(@account).paginate_by_max_id(limit_param(DEFAULT_STATUSES_LIMIT), params[:max_id], params[:since_id])
  8. @statuses = cache_collection(@statuses)
  9. set_maps(@statuses)
  10. # Since the statuses are in reverse chronological order, last is the lowest ID.
  11. @next_path = api_activitypub_outbox_url(max_id: @statuses.last.id) if @statuses.size == limit_param(DEFAULT_STATUSES_LIMIT)
  12. unless @statuses.empty?
  13. if @statuses.first.id == 1
  14. @prev_path = api_activitypub_outbox_url
  15. elsif params[:max_id]
  16. @prev_path = api_activitypub_outbox_url(since_id: @statuses.first.id)
  17. end
  18. end
  19. @paginated = @next_path || @prev_path
  20. set_pagination_headers(@next_path, @prev_path)
  21. end
  22. private
  23. def cache_collection(raw)
  24. super(raw, Status)
  25. end
  26. def set_account
  27. @account = Account.find(params[:id])
  28. end
  29. end