The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

76 lines
1.8 KiB

  1. # frozen_string_literal: true
  2. class Api::V1::Statuses::RebloggedByAccountsController < Api::BaseController
  3. include Authorization
  4. before_action -> { authorize_if_got_token! :read, :'read:accounts' }
  5. before_action :set_status
  6. after_action :insert_pagination_headers
  7. respond_to :json
  8. def index
  9. @accounts = load_accounts
  10. render json: @accounts, each_serializer: REST::AccountSerializer
  11. end
  12. private
  13. def load_accounts
  14. scope = default_accounts
  15. scope = scope.where.not(id: current_account.excluded_from_timeline_account_ids) unless current_account.nil?
  16. scope.merge(paginated_statuses).to_a
  17. end
  18. def default_accounts
  19. Account.includes(:statuses, :account_stat).references(:statuses)
  20. end
  21. def paginated_statuses
  22. Status.where(reblog_of_id: @status.id).where(visibility: [:public, :unlisted]).paginate_by_max_id(
  23. limit_param(DEFAULT_ACCOUNTS_LIMIT),
  24. params[:max_id],
  25. params[:since_id]
  26. )
  27. end
  28. def insert_pagination_headers
  29. set_pagination_headers(next_path, prev_path)
  30. end
  31. def next_path
  32. if records_continue?
  33. api_v1_status_reblogged_by_index_url pagination_params(max_id: pagination_max_id)
  34. end
  35. end
  36. def prev_path
  37. unless @accounts.empty?
  38. api_v1_status_reblogged_by_index_url pagination_params(since_id: pagination_since_id)
  39. end
  40. end
  41. def pagination_max_id
  42. @accounts.last.statuses.last.id
  43. end
  44. def pagination_since_id
  45. @accounts.first.statuses.first.id
  46. end
  47. def records_continue?
  48. @accounts.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
  49. end
  50. def set_status
  51. @status = Status.find(params[:status_id])
  52. authorize @status, :show?
  53. rescue Mastodon::NotPermittedError
  54. not_found
  55. end
  56. def pagination_params(core_params)
  57. params.slice(:limit).permit(:limit).merge(core_params)
  58. end
  59. end