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.4 KiB

  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. )
  29. end
  30. def list_feed
  31. ListFeed.new(@list)
  32. end
  33. def insert_pagination_headers
  34. set_pagination_headers(next_path, prev_path)
  35. end
  36. def pagination_params(core_params)
  37. params.slice(:limit).permit(:limit).merge(core_params)
  38. end
  39. def next_path
  40. api_v1_timelines_list_url params[:id], pagination_params(max_id: pagination_max_id)
  41. end
  42. def prev_path
  43. api_v1_timelines_list_url params[:id], pagination_params(since_id: pagination_since_id)
  44. end
  45. def pagination_max_id
  46. @statuses.last.id
  47. end
  48. def pagination_since_id
  49. @statuses.first.id
  50. end
  51. end