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.

42 lines
1.1 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
  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: @reblog.id)
  14. if @status
  15. authorize @status, :unreblog?
  16. @status.discard
  17. RemovalWorker.perform_async(@status.id)
  18. end
  19. render json: @reblog, serializer: REST::StatusSerializer, relationships: StatusRelationshipsPresenter.new([@status], current_account.id, reblogs_map: { @reblog.id => false })
  20. end
  21. private
  22. def set_reblog
  23. @reblog = Status.find(params[:status_id])
  24. authorize @reblog, :show?
  25. rescue Mastodon::NotPermittedError
  26. not_found
  27. end
  28. def reblog_params
  29. params.permit(:visibility)
  30. end
  31. end