diff --git a/app/controllers/api/v1/statuses_controller.rb b/app/controllers/api/v1/statuses_controller.rb index 19cc71ae58..2027bc6016 100644 --- a/app/controllers/api/v1/statuses_controller.rb +++ b/app/controllers/api/v1/statuses_controller.rb @@ -111,7 +111,7 @@ class Api::V1::StatusesController < Api::BaseController @status.account.statuses_count = @status.account.statuses_count - 1 json = render_to_body json: @status, serializer: REST::StatusSerializer, source_requested: true - RemovalWorker.perform_async(@status.id, { 'redraft' => true }) + RemovalWorker.perform_async(@status.id, { 'redraft' => !truthy_param?(:delete_media) }) render json: json end diff --git a/app/javascript/mastodon/actions/statuses.js b/app/javascript/mastodon/actions/statuses.js index 1e4e545d8c..1e5b53c687 100644 --- a/app/javascript/mastodon/actions/statuses.js +++ b/app/javascript/mastodon/actions/statuses.js @@ -138,7 +138,7 @@ export function deleteStatus(id, withRedraft = false) { dispatch(deleteStatusRequest(id)); - api().delete(`/api/v1/statuses/${id}`).then(response => { + api().delete(`/api/v1/statuses/${id}`, { params: { delete_media: !withRedraft } }).then(response => { dispatch(deleteStatusSuccess(id)); dispatch(deleteFromTimelines(id)); dispatch(importFetchedAccount(response.data.account)); diff --git a/spec/requests/api/v1/statuses_spec.rb b/spec/requests/api/v1/statuses_spec.rb index ddf5945d25..285fa93655 100644 --- a/spec/requests/api/v1/statuses_spec.rb +++ b/spec/requests/api/v1/statuses_spec.rb @@ -257,13 +257,30 @@ RSpec.describe '/api/v1/statuses' do it_behaves_like 'forbidden for wrong scope', 'read read:statuses' - it 'removes the status', :aggregate_failures do + it 'discards the status and schedules removal as a redraft', :aggregate_failures do subject expect(response).to have_http_status(200) expect(response.content_type) .to start_with('application/json') expect(Status.find_by(id: status.id)).to be_nil + expect(RemovalWorker).to have_enqueued_sidekiq_job(status.id, { 'redraft' => true }) + end + + context 'when called with truthy delete_media' do + subject do + delete "/api/v1/statuses/#{status.id}?delete_media=true", headers: headers + end + + it 'discards the status and schedules removal without the redraft flag', :aggregate_failures do + subject + + expect(response).to have_http_status(200) + expect(response.content_type) + .to start_with('application/json') + expect(Status.find_by(id: status.id)).to be_nil + expect(RemovalWorker).to have_enqueued_sidekiq_job(status.id, { 'redraft' => false }) + end end end