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.

71 lines
1.6 KiB

  1. # frozen_string_literal: true
  2. class Api::V1::Timelines::TagController < Api::BaseController
  3. before_action :load_tag
  4. after_action :insert_pagination_headers, unless: -> { @statuses.empty? }
  5. def show
  6. @statuses = load_statuses
  7. render json: @statuses, each_serializer: REST::StatusSerializer, relationships: StatusRelationshipsPresenter.new(@statuses, current_user&.account_id)
  8. end
  9. private
  10. def load_tag
  11. @tag = Tag.find_normalized(params[:id])
  12. end
  13. def load_statuses
  14. cached_tagged_statuses
  15. end
  16. def cached_tagged_statuses
  17. @tag.nil? ? [] : cache_collection(tag_timeline_statuses, Status)
  18. end
  19. def tag_timeline_statuses
  20. tag_feed.get(
  21. limit_param(DEFAULT_STATUSES_LIMIT),
  22. params[:max_id],
  23. params[:since_id],
  24. params[:min_id]
  25. )
  26. end
  27. def tag_feed
  28. TagFeed.new(
  29. @tag,
  30. current_account,
  31. any: params[:any],
  32. all: params[:all],
  33. none: params[:none],
  34. local: truthy_param?(:local),
  35. remote: truthy_param?(:remote),
  36. only_media: truthy_param?(:only_media)
  37. )
  38. end
  39. def insert_pagination_headers
  40. set_pagination_headers(next_path, prev_path)
  41. end
  42. def pagination_params(core_params)
  43. params.slice(:local, :limit, :only_media).permit(:local, :limit, :only_media).merge(core_params)
  44. end
  45. def next_path
  46. api_v1_timelines_tag_url params[:id], pagination_params(max_id: pagination_max_id)
  47. end
  48. def prev_path
  49. api_v1_timelines_tag_url params[:id], pagination_params(min_id: pagination_since_id)
  50. end
  51. def pagination_max_id
  52. @statuses.last.id
  53. end
  54. def pagination_since_id
  55. @statuses.first.id
  56. end
  57. end