闭社主体 forked from https://github.com/tootsuite/mastodon
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.

43 lines
949 B

  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)
  30. log_action :destroy, status
  31. end
  32. true
  33. end
  34. end