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.

61 lines
2.1 KiB

  1. # frozen_string_literal: true
  2. class Api::V1::TimelinesController < ApiController
  3. before_action -> { doorkeeper_authorize! :read }, only: [:home]
  4. before_action :require_user!, only: [:home]
  5. respond_to :json
  6. def home
  7. @statuses = Feed.new(:home, current_account).get(limit_param(DEFAULT_STATUSES_LIMIT), params[:max_id], params[:since_id])
  8. @statuses = cache_collection(@statuses)
  9. set_maps(@statuses)
  10. next_path = api_v1_home_timeline_url(pagination_params(max_id: @statuses.last.id)) unless @statuses.empty?
  11. prev_path = api_v1_home_timeline_url(pagination_params(since_id: @statuses.first.id)) unless @statuses.empty?
  12. set_pagination_headers(next_path, prev_path)
  13. render :index
  14. end
  15. def public
  16. @statuses = Status.as_public_timeline(current_account, params[:local]).paginate_by_max_id(limit_param(DEFAULT_STATUSES_LIMIT), params[:max_id], params[:since_id])
  17. @statuses = cache_collection(@statuses)
  18. set_maps(@statuses)
  19. next_path = api_v1_public_timeline_url(pagination_params(max_id: @statuses.last.id)) unless @statuses.empty?
  20. prev_path = api_v1_public_timeline_url(pagination_params(since_id: @statuses.first.id)) unless @statuses.empty?
  21. set_pagination_headers(next_path, prev_path)
  22. render :index
  23. end
  24. def tag
  25. @tag = Tag.find_by(name: params[:id].downcase)
  26. @statuses = @tag.nil? ? [] : Status.as_tag_timeline(@tag, current_account, params[:local]).paginate_by_max_id(limit_param(DEFAULT_STATUSES_LIMIT), params[:max_id], params[:since_id])
  27. @statuses = cache_collection(@statuses)
  28. set_maps(@statuses)
  29. next_path = api_v1_hashtag_timeline_url(params[:id], pagination_params(max_id: @statuses.last.id)) unless @statuses.empty?
  30. prev_path = api_v1_hashtag_timeline_url(params[:id], pagination_params(since_id: @statuses.first.id)) unless @statuses.empty?
  31. set_pagination_headers(next_path, prev_path)
  32. render :index
  33. end
  34. private
  35. def cache_collection(raw)
  36. super(raw, Status)
  37. end
  38. def pagination_params(core_params)
  39. params.permit(:local, :limit).merge(core_params)
  40. end
  41. end