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.

62 lines
1.3 KiB

  1. # frozen_string_literal: true
  2. class Api::V1::Timelines::HomeController < Api::BaseController
  3. before_action -> { doorkeeper_authorize! :read }, only: [:show]
  4. before_action :require_user!, only: [:show]
  5. after_action :insert_pagination_headers, unless: -> { @statuses.empty? }
  6. respond_to :json
  7. def show
  8. @statuses = load_statuses
  9. render 'api/v1/timelines/show'
  10. end
  11. private
  12. def load_statuses
  13. cached_home_statuses.tap do |statuses|
  14. set_maps(statuses)
  15. end
  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. )
  26. end
  27. def account_home_feed
  28. Feed.new(:home, current_account)
  29. end
  30. def insert_pagination_headers
  31. set_pagination_headers(next_path, prev_path)
  32. end
  33. def pagination_params(core_params)
  34. params.permit(:local, :limit).merge(core_params)
  35. end
  36. def next_path
  37. api_v1_timelines_home_url pagination_params(max_id: pagination_max_id)
  38. end
  39. def prev_path
  40. api_v1_timelines_home_url pagination_params(since_id: pagination_since_id)
  41. end
  42. def pagination_max_id
  43. @statuses.last.id
  44. end
  45. def pagination_since_id
  46. @statuses.first.id
  47. end
  48. end