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.

48 lines
1.3 KiB

  1. # frozen_string_literal: true
  2. class Api::V1::Statuses::ReblogsController < Api::BaseController
  3. include Authorization
  4. before_action -> { doorkeeper_authorize! :write, :'write:statuses' }
  5. before_action :require_user!
  6. before_action :set_reblog, only: [:create]
  7. override_rate_limit_headers :create, family: :statuses
  8. def create
  9. @status = ReblogService.new.call(current_account, @reblog, reblog_params)
  10. render json: @status, serializer: REST::StatusSerializer
  11. end
  12. def destroy
  13. @status = current_account.statuses.find_by(reblog_of_id: params[:status_id])
  14. if @status
  15. authorize @status, :unreblog?
  16. @status.discard
  17. RemovalWorker.perform_async(@status.id)
  18. @reblog = @status.reblog
  19. else
  20. @reblog = Status.find(params[:status_id])
  21. authorize @reblog, :show?
  22. end
  23. render json: @reblog, serializer: REST::StatusSerializer, relationships: StatusRelationshipsPresenter.new([@status], current_account.id, reblogs_map: { @reblog.id => false })
  24. rescue Mastodon::NotPermittedError
  25. not_found
  26. end
  27. private
  28. def set_reblog
  29. @reblog = Status.find(params[:status_id])
  30. authorize @reblog, :show?
  31. rescue Mastodon::NotPermittedError
  32. not_found
  33. end
  34. def reblog_params
  35. params.permit(:visibility)
  36. end
  37. end