闭社主体 forked from https://github.com/tootsuite/mastodon
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.

63 lines
2.4 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(limit_param(DEFAULT_STATUSES_LIMIT), params[:max_id], params[:since_id])
  8. @statuses = cache_collection(@statuses)
  9. set_maps(@statuses)
  10. set_counters_maps(@statuses)
  11. set_account_counters_maps(@statuses.flat_map { |s| [s.account, s.reblog? ? s.reblog.account : nil] }.compact.uniq)
  12. next_path = api_v1_home_timeline_url(max_id: @statuses.last.id) if @statuses.size == limit_param(DEFAULT_STATUSES_LIMIT)
  13. prev_path = api_v1_home_timeline_url(since_id: @statuses.first.id) unless @statuses.empty?
  14. set_pagination_headers(next_path, prev_path)
  15. render action: :index
  16. end
  17. def public
  18. @statuses = Status.as_public_timeline(current_account).paginate_by_max_id(limit_param(DEFAULT_STATUSES_LIMIT), params[:max_id], params[:since_id])
  19. @statuses = cache_collection(@statuses)
  20. set_maps(@statuses)
  21. set_counters_maps(@statuses)
  22. set_account_counters_maps(@statuses.flat_map { |s| [s.account, s.reblog? ? s.reblog.account : nil] }.compact.uniq)
  23. next_path = api_v1_public_timeline_url(max_id: @statuses.last.id) if @statuses.size == limit_param(DEFAULT_STATUSES_LIMIT)
  24. prev_path = api_v1_public_timeline_url(since_id: @statuses.first.id) unless @statuses.empty?
  25. set_pagination_headers(next_path, prev_path)
  26. render action: :index
  27. end
  28. def tag
  29. @tag = Tag.find_by(name: params[:id].downcase)
  30. @statuses = @tag.nil? ? [] : Status.as_tag_timeline(@tag, current_account).paginate_by_max_id(limit_param(DEFAULT_STATUSES_LIMIT), params[:max_id], params[:since_id])
  31. @statuses = cache_collection(@statuses)
  32. set_maps(@statuses)
  33. set_counters_maps(@statuses)
  34. set_account_counters_maps(@statuses.flat_map { |s| [s.account, s.reblog? ? s.reblog.account : nil] }.compact.uniq)
  35. next_path = api_v1_hashtag_timeline_url(params[:id], max_id: @statuses.last.id) if @statuses.size == limit_param(DEFAULT_STATUSES_LIMIT)
  36. prev_path = api_v1_hashtag_timeline_url(params[:id], since_id: @statuses.first.id) unless @statuses.empty?
  37. set_pagination_headers(next_path, prev_path)
  38. render action: :index
  39. end
  40. private
  41. def cache_collection(raw)
  42. super(raw, Status)
  43. end
  44. end