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.

60 lines
1.2 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 'api/v1/timelines/show'
  8. end
  9. private
  10. def load_statuses
  11. cached_public_statuses.tap do |statuses|
  12. set_maps(statuses)
  13. end
  14. end
  15. def cached_public_statuses
  16. cache_collection public_statuses, Status
  17. end
  18. def public_statuses
  19. public_timeline_statuses.paginate_by_max_id(
  20. limit_param(DEFAULT_STATUSES_LIMIT),
  21. params[:max_id],
  22. params[:since_id]
  23. )
  24. end
  25. def public_timeline_statuses
  26. Status.as_public_timeline(current_account, params[:local])
  27. end
  28. def insert_pagination_headers
  29. set_pagination_headers(next_path, prev_path)
  30. end
  31. def pagination_params(core_params)
  32. params.permit(:local, :limit).merge(core_params)
  33. end
  34. def next_path
  35. api_v1_timelines_public_url pagination_params(max_id: pagination_max_id)
  36. end
  37. def prev_path
  38. api_v1_timelines_public_url pagination_params(since_id: pagination_since_id)
  39. end
  40. def pagination_max_id
  41. @statuses.last.id
  42. end
  43. def pagination_since_id
  44. @statuses.first.id
  45. end
  46. end