闭社主体 forked from https://github.com/tootsuite/mastodon
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.

69 lines
1.7 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. if params[:max_id] || params[:since_id]
  7. show_outbox_page
  8. else
  9. show_base_outbox
  10. end
  11. end
  12. private
  13. def show_base_outbox
  14. @statuses = Status.as_outbox_timeline(@account)
  15. @statuses = cache_collection(@statuses)
  16. set_maps(@statuses)
  17. set_first_last_page(@statuses)
  18. render :show
  19. end
  20. def show_outbox_page
  21. all_statuses = Status.as_outbox_timeline(@account)
  22. @statuses = all_statuses.paginate_by_max_id(limit_param(DEFAULT_STATUSES_LIMIT), params[:max_id], params[:since_id])
  23. all_statuses = cache_collection(all_statuses)
  24. @statuses = cache_collection(@statuses)
  25. set_maps(@statuses)
  26. set_first_last_page(all_statuses)
  27. @next_page_url = api_activitypub_outbox_url(pagination_params(max_id: @statuses.last.id)) unless @statuses.empty?
  28. @prev_page_url = api_activitypub_outbox_url(pagination_params(since_id: @statuses.first.id)) unless @statuses.empty?
  29. @paginated = @next_page_url || @prev_page_url
  30. @part_of_url = api_activitypub_outbox_url
  31. set_pagination_headers(@next_page_url, @prev_page_url)
  32. render :show_page
  33. end
  34. def cache_collection(raw)
  35. super(raw, Status)
  36. end
  37. def set_account
  38. @account = Account.find(params[:id])
  39. end
  40. def set_first_last_page(statuses) # rubocop:disable Style/AccessorMethodName
  41. return if statuses.empty?
  42. @first_page_url = api_activitypub_outbox_url(max_id: statuses.first.id + 1)
  43. @last_page_url = api_activitypub_outbox_url(since_id: statuses.last.id - 1)
  44. end
  45. def pagination_params(core_params)
  46. params.permit(:local, :limit).merge(core_params)
  47. end
  48. end