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.

58 lines
1.3 KiB

  1. # frozen_string_literal: true
  2. class Api::V1::Timelines::PublicController < Api::BaseController
  3. after_action :insert_pagination_headers, unless: -> { @statuses.empty? }
  4. respond_to :json
  5. def show
  6. @statuses = load_statuses
  7. render json: @statuses, each_serializer: REST::StatusSerializer, relationships: StatusRelationshipsPresenter.new(@statuses, current_user&.account_id)
  8. end
  9. private
  10. def load_statuses
  11. cached_public_statuses
  12. end
  13. def cached_public_statuses
  14. cache_collection public_statuses, Status
  15. end
  16. def public_statuses
  17. public_timeline_statuses.paginate_by_max_id(
  18. limit_param(DEFAULT_STATUSES_LIMIT),
  19. params[:max_id],
  20. params[:since_id]
  21. )
  22. end
  23. def public_timeline_statuses
  24. Status.as_public_timeline(current_account, params[:local])
  25. end
  26. def insert_pagination_headers
  27. set_pagination_headers(next_path, prev_path)
  28. end
  29. def pagination_params(core_params)
  30. params.permit(:local, :limit).merge(core_params)
  31. end
  32. def next_path
  33. api_v1_timelines_public_url pagination_params(max_id: pagination_max_id)
  34. end
  35. def prev_path
  36. api_v1_timelines_public_url pagination_params(since_id: pagination_since_id)
  37. end
  38. def pagination_max_id
  39. @statuses.last.id
  40. end
  41. def pagination_since_id
  42. @statuses.first.id
  43. end
  44. end