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.

69 lines
2.7 KiB

  1. # frozen_string_literal: true
  2. class Api::V1::TimelinesController < ApiController
  3. before_action -> { doorkeeper_authorize! :read }
  4. before_action :require_user!, only: [:home, :mentions]
  5. respond_to :json
  6. def home
  7. @statuses = Feed.new(:home, current_account).get(DEFAULT_STATUSES_LIMIT, params[:max_id], params[:since_id]).to_a
  8. set_maps(@statuses)
  9. set_counters_maps(@statuses)
  10. set_account_counters_maps(@statuses.flat_map { |s| [s.account, s.reblog? ? s.reblog.account : nil] }.compact.uniq)
  11. next_path = api_v1_home_timeline_url(max_id: @statuses.last.id) if @statuses.size == DEFAULT_STATUSES_LIMIT
  12. prev_path = api_v1_home_timeline_url(since_id: @statuses.first.id) unless @statuses.empty?
  13. set_pagination_headers(next_path, prev_path)
  14. render action: :index
  15. end
  16. def mentions
  17. @statuses = Feed.new(:mentions, current_account).get(DEFAULT_STATUSES_LIMIT, params[:max_id], params[:since_id]).to_a
  18. set_maps(@statuses)
  19. set_counters_maps(@statuses)
  20. set_account_counters_maps(@statuses.flat_map { |s| [s.account, s.reblog? ? s.reblog.account : nil] }.compact.uniq)
  21. next_path = api_v1_mentions_timeline_url(max_id: @statuses.last.id) if @statuses.size == DEFAULT_STATUSES_LIMIT
  22. prev_path = api_v1_mentions_timeline_url(since_id: @statuses.first.id) unless @statuses.empty?
  23. set_pagination_headers(next_path, prev_path)
  24. render action: :index
  25. end
  26. def public
  27. @statuses = Status.as_public_timeline(current_account).paginate_by_max_id(DEFAULT_STATUSES_LIMIT, params[:max_id], params[:since_id]).to_a
  28. set_maps(@statuses)
  29. set_counters_maps(@statuses)
  30. set_account_counters_maps(@statuses.flat_map { |s| [s.account, s.reblog? ? s.reblog.account : nil] }.compact.uniq)
  31. next_path = api_v1_public_timeline_url(max_id: @statuses.last.id) if @statuses.size == DEFAULT_STATUSES_LIMIT
  32. prev_path = api_v1_public_timeline_url(since_id: @statuses.first.id) unless @statuses.empty?
  33. set_pagination_headers(next_path, prev_path)
  34. render action: :index
  35. end
  36. def tag
  37. @tag = Tag.find_by(name: params[:id].downcase)
  38. @statuses = @tag.nil? ? [] : Status.as_tag_timeline(@tag, current_account).paginate_by_max_id(DEFAULT_STATUSES_LIMIT, params[:max_id], params[:since_id]).to_a
  39. set_maps(@statuses)
  40. set_counters_maps(@statuses)
  41. set_account_counters_maps(@statuses.flat_map { |s| [s.account, s.reblog? ? s.reblog.account : nil] }.compact.uniq)
  42. next_path = api_v1_hashtag_timeline_url(params[:id], max_id: @statuses.last.id) if @statuses.size == DEFAULT_STATUSES_LIMIT
  43. prev_path = api_v1_hashtag_timeline_url(params[:id], since_id: @statuses.first.id) unless @statuses.empty?
  44. set_pagination_headers(next_path, prev_path)
  45. render action: :index
  46. end
  47. end