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.

63 lines
1.4 KiB

  1. # frozen_string_literal: true
  2. class Api::V1::Timelines::HomeController < Api::BaseController
  3. before_action -> { doorkeeper_authorize! :read, :'read:statuses' }, only: [:show]
  4. before_action :require_user!, only: [:show]
  5. after_action :insert_pagination_headers, unless: -> { @statuses.empty? }
  6. def show
  7. @statuses = load_statuses
  8. render json: @statuses,
  9. each_serializer: REST::StatusSerializer,
  10. relationships: StatusRelationshipsPresenter.new(@statuses, current_user&.account_id),
  11. status: account_home_feed.regenerating? ? 206 : 200
  12. end
  13. private
  14. def load_statuses
  15. cached_home_statuses
  16. end
  17. def cached_home_statuses
  18. cache_collection home_statuses, Status
  19. end
  20. def home_statuses
  21. account_home_feed.get(
  22. limit_param(DEFAULT_STATUSES_LIMIT),
  23. params[:max_id],
  24. params[:since_id],
  25. params[:min_id]
  26. )
  27. end
  28. def account_home_feed
  29. HomeFeed.new(current_account)
  30. end
  31. def insert_pagination_headers
  32. set_pagination_headers(next_path, prev_path)
  33. end
  34. def pagination_params(core_params)
  35. params.slice(:local, :limit).permit(:local, :limit).merge(core_params)
  36. end
  37. def next_path
  38. api_v1_timelines_home_url pagination_params(max_id: pagination_max_id)
  39. end
  40. def prev_path
  41. api_v1_timelines_home_url pagination_params(min_id: pagination_since_id)
  42. end
  43. def pagination_max_id
  44. @statuses.last.id
  45. end
  46. def pagination_since_id
  47. @statuses.first.id
  48. end
  49. end