闭社主体 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.

61 lines
2.1 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. next_path = api_v1_home_timeline_url(max_id: @statuses.last.id) if @statuses.size == DEFAULT_STATUSES_LIMIT
  10. prev_path = api_v1_home_timeline_url(since_id: @statuses.first.id) unless @statuses.empty?
  11. set_pagination_headers(next_path, prev_path)
  12. render action: :index
  13. end
  14. def mentions
  15. @statuses = Feed.new(:mentions, current_account).get(DEFAULT_STATUSES_LIMIT, params[:max_id], params[:since_id]).to_a
  16. set_maps(@statuses)
  17. next_path = api_v1_mentions_timeline_url(max_id: @statuses.last.id) if @statuses.size == DEFAULT_STATUSES_LIMIT
  18. prev_path = api_v1_mentions_timeline_url(since_id: @statuses.first.id) unless @statuses.empty?
  19. set_pagination_headers(next_path, prev_path)
  20. render action: :index
  21. end
  22. def public
  23. @statuses = Status.as_public_timeline(current_account).paginate_by_max_id(DEFAULT_STATUSES_LIMIT, params[:max_id], params[:since_id]).to_a
  24. set_maps(@statuses)
  25. next_path = api_v1_public_timeline_url(max_id: @statuses.last.id) if @statuses.size == DEFAULT_STATUSES_LIMIT
  26. prev_path = api_v1_public_timeline_url(since_id: @statuses.first.id) unless @statuses.empty?
  27. set_pagination_headers(next_path, prev_path)
  28. render action: :index
  29. end
  30. def tag
  31. @tag = Tag.find_by(name: params[:id].downcase)
  32. @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
  33. set_maps(@statuses)
  34. next_path = api_v1_hashtag_timeline_url(params[:id], max_id: @statuses.last.id) if @statuses.size == DEFAULT_STATUSES_LIMIT
  35. prev_path = api_v1_hashtag_timeline_url(params[:id], since_id: @statuses.first.id) unless @statuses.empty?
  36. set_pagination_headers(next_path, prev_path)
  37. render action: :index
  38. end
  39. end