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.

59 lines
2.1 KiB

  1. class Api::V1::TimelinesController < ApiController
  2. before_action -> { doorkeeper_authorize! :read }
  3. before_action :require_user!, only: [:home, :mentions]
  4. respond_to :json
  5. def home
  6. @statuses = Feed.new(:home, current_account).get(DEFAULT_STATUSES_LIMIT, params[:max_id], params[:since_id]).to_a
  7. set_maps(@statuses)
  8. next_path = api_v1_home_timeline_url(max_id: @statuses.last.id) if @statuses.size == DEFAULT_STATUSES_LIMIT
  9. prev_path = api_v1_home_timeline_url(since_id: @statuses.first.id) if @statuses.size > 0
  10. set_pagination_headers(next_path, prev_path)
  11. render action: :index
  12. end
  13. def mentions
  14. @statuses = Feed.new(:mentions, current_account).get(DEFAULT_STATUSES_LIMIT, params[:max_id], params[:since_id]).to_a
  15. set_maps(@statuses)
  16. next_path = api_v1_mentions_timeline_url(max_id: @statuses.last.id) if @statuses.size == DEFAULT_STATUSES_LIMIT
  17. prev_path = api_v1_mentions_timeline_url(since_id: @statuses.first.id) if @statuses.size > 0
  18. set_pagination_headers(next_path, prev_path)
  19. render action: :index
  20. end
  21. def public
  22. @statuses = Status.as_public_timeline(current_account).paginate_by_max_id(DEFAULT_STATUSES_LIMIT, params[:max_id], params[:since_id]).to_a
  23. set_maps(@statuses)
  24. next_path = api_v1_public_timeline_url(max_id: @statuses.last.id) if @statuses.size == DEFAULT_STATUSES_LIMIT
  25. prev_path = api_v1_public_timeline_url(since_id: @statuses.first.id) if @statuses.size > 0
  26. set_pagination_headers(next_path, prev_path)
  27. render action: :index
  28. end
  29. def tag
  30. @tag = Tag.find_by(name: params[:id].downcase)
  31. @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
  32. set_maps(@statuses)
  33. next_path = api_v1_hashtag_timeline_url(params[:id], max_id: @statuses.last.id) if @statuses.size == DEFAULT_STATUSES_LIMIT
  34. prev_path = api_v1_hashtag_timeline_url(params[:id], since_id: @statuses.first.id) if @statuses.size > 0
  35. set_pagination_headers(next_path, prev_path)
  36. render action: :index
  37. end
  38. end