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.

39 lines
856 B

  1. # frozen_string_literal: true
  2. class Form::StatusBatch
  3. include ActiveModel::Model
  4. attr_accessor :status_ids, :action
  5. ACTION_TYPE = %w(nsfw_on nsfw_off delete).freeze
  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).find_each do |status|
  19. status.update!(sensitive: sensitive)
  20. end
  21. end
  22. true
  23. rescue ActiveRecord::RecordInvalid
  24. false
  25. end
  26. def delete_statuses
  27. Status.where(id: status_ids).find_each do |status|
  28. RemovalWorker.perform_async(status.id)
  29. end
  30. true
  31. end
  32. end