The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

66 lines
1.5 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. respond_to :json
  7. def show
  8. @statuses = load_statuses
  9. render json: @statuses,
  10. each_serializer: REST::StatusSerializer,
  11. relationships: StatusRelationshipsPresenter.new(@statuses, current_user&.account_id),
  12. status: account_home_feed.regenerating? ? 206 : 200
  13. end
  14. private
  15. def load_statuses
  16. cached_home_statuses
  17. end
  18. def cached_home_statuses
  19. cache_collection home_statuses, Status
  20. end
  21. def home_statuses
  22. account_home_feed.get(
  23. limit_param(DEFAULT_STATUSES_LIMIT),
  24. params[:max_id],
  25. params[:since_id],
  26. params[:min_id]
  27. )
  28. end
  29. def account_home_feed
  30. HomeFeed.new(current_account)
  31. end
  32. def insert_pagination_headers
  33. set_pagination_headers(next_path, prev_path)
  34. end
  35. def pagination_params(core_params)
  36. params.slice(:local, :limit).permit(:local, :limit).merge(core_params)
  37. end
  38. def next_path
  39. api_v1_timelines_home_url pagination_params(max_id: pagination_max_id)
  40. end
  41. def prev_path
  42. api_v1_timelines_home_url pagination_params(min_id: pagination_since_id)
  43. end
  44. def pagination_max_id
  45. @statuses.last.id
  46. end
  47. def pagination_since_id
  48. @statuses.first.id
  49. end
  50. end