list_controller.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # frozen_string_literal: true
  2. class Api::V1::Timelines::ListController < Api::BaseController
  3. before_action -> { doorkeeper_authorize! :read, :'read:lists' }
  4. before_action :require_user!
  5. before_action :set_list
  6. before_action :set_statuses
  7. after_action :insert_pagination_headers, unless: -> { @statuses.empty? }
  8. def show
  9. render json: @statuses,
  10. each_serializer: REST::StatusSerializer,
  11. relationships: StatusRelationshipsPresenter.new(@statuses, current_user.account_id)
  12. end
  13. private
  14. def set_list
  15. @list = List.where(account: current_account).find(params[:id])
  16. end
  17. def set_statuses
  18. @statuses = cached_list_statuses
  19. end
  20. def cached_list_statuses
  21. cache_collection list_statuses, Status
  22. end
  23. def list_statuses
  24. list_feed.get(
  25. limit_param(DEFAULT_STATUSES_LIMIT),
  26. params[:max_id],
  27. params[:since_id],
  28. params[:min_id]
  29. )
  30. end
  31. def list_feed
  32. ListFeed.new(@list)
  33. end
  34. def insert_pagination_headers
  35. set_pagination_headers(next_path, prev_path)
  36. end
  37. def pagination_params(core_params)
  38. params.slice(:limit).permit(:limit).merge(core_params)
  39. end
  40. def next_path
  41. api_v1_timelines_list_url params[:id], pagination_params(max_id: pagination_max_id)
  42. end
  43. def prev_path
  44. api_v1_timelines_list_url params[:id], pagination_params(min_id: pagination_since_id)
  45. end
  46. def pagination_max_id
  47. @statuses.last.id
  48. end
  49. def pagination_since_id
  50. @statuses.first.id
  51. end
  52. end