logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

status_batch.rb (975B)


  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. ACTION_TYPE = %w(nsfw_on nsfw_off delete).freeze
  7. def save
  8. case action
  9. when 'nsfw_on', 'nsfw_off'
  10. change_sensitive(action == 'nsfw_on')
  11. when 'delete'
  12. delete_statuses
  13. end
  14. end
  15. private
  16. def change_sensitive(sensitive)
  17. media_attached_status_ids = MediaAttachment.where(status_id: status_ids).pluck(:status_id)
  18. ApplicationRecord.transaction do
  19. Status.where(id: media_attached_status_ids).find_each do |status|
  20. status.update!(sensitive: sensitive)
  21. log_action :update, status
  22. end
  23. end
  24. true
  25. rescue ActiveRecord::RecordInvalid
  26. false
  27. end
  28. def delete_statuses
  29. Status.where(id: status_ids).find_each do |status|
  30. RemovalWorker.perform_async(status.id)
  31. log_action :destroy, status
  32. end
  33. true
  34. end
  35. end