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.

41 lines
982 B

  1. # frozen_string_literal: true
  2. class Api::V1::Statuses::MutesController < Api::BaseController
  3. include Authorization
  4. before_action -> { doorkeeper_authorize! :write }
  5. before_action :require_user!
  6. before_action :set_status
  7. before_action :set_conversation
  8. respond_to :json
  9. def create
  10. current_account.mute_conversation!(@conversation)
  11. @mutes_map = { @conversation.id => true }
  12. render 'api/v1/statuses/show'
  13. end
  14. def destroy
  15. current_account.unmute_conversation!(@conversation)
  16. @mutes_map = { @conversation.id => false }
  17. render 'api/v1/statuses/show'
  18. end
  19. private
  20. def set_status
  21. @status = Status.find(params[:status_id])
  22. authorize @status, :show?
  23. rescue Mastodon::NotPermittedError
  24. # Reraise in order to get a 404 instead of a 403 error code
  25. raise ActiveRecord::RecordNotFound
  26. end
  27. def set_conversation
  28. @conversation = @status.conversation
  29. raise Mastodon::ValidationError if @conversation.nil?
  30. end
  31. end