status_batch.rb 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # frozen_string_literal: true
  2. class Form::StatusBatch
  3. include ActiveModel::Model
  4. include AccountableConcern
  5. attr_accessor :status_ids, :action, :current_account
  6. def save
  7. case action
  8. when 'nsfw_on', 'nsfw_off'
  9. change_sensitive(action == 'nsfw_on')
  10. when 'delete'
  11. delete_statuses
  12. end
  13. end
  14. private
  15. def change_sensitive(sensitive)
  16. media_attached_status_ids = MediaAttachment.where(status_id: status_ids).pluck(:status_id)
  17. ApplicationRecord.transaction do
  18. Status.where(id: media_attached_status_ids).reorder(nil).find_each do |status|
  19. status.update!(sensitive: sensitive)
  20. log_action :update, status
  21. end
  22. end
  23. true
  24. rescue ActiveRecord::RecordInvalid
  25. false
  26. end
  27. def delete_statuses
  28. Status.where(id: status_ids).reorder(nil).find_each do |status|
  29. RemovalWorker.perform_async(status.id, redraft: false)
  30. Tombstone.find_or_create_by(uri: status.uri, account: status.account, by_moderator: true)
  31. log_action :destroy, status
  32. end
  33. true
  34. end
  35. end