1
0

block_domain_service.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # frozen_string_literal: true
  2. class BlockDomainService < BaseService
  3. attr_reader :domain_block
  4. def call(domain_block, update = false)
  5. @domain_block = domain_block
  6. process_domain_block!
  7. process_retroactive_updates! if update
  8. end
  9. private
  10. def process_retroactive_updates!
  11. # If the domain block severity has been changed, undo the appropriate limitations
  12. scope = Account.by_domain_and_subdomains(domain_block.domain)
  13. scope.where(silenced_at: domain_block.created_at).in_batches.update_all(silenced_at: nil) unless domain_block.silence?
  14. scope.where(suspended_at: domain_block.created_at).in_batches.update_all(suspended_at: nil, suspension_origin: nil) unless domain_block.suspend?
  15. end
  16. def process_domain_block!
  17. if domain_block.silence?
  18. silence_accounts!
  19. elsif domain_block.suspend?
  20. suspend_accounts!
  21. end
  22. DomainClearMediaWorker.perform_async(domain_block.id) if domain_block.reject_media?
  23. end
  24. def silence_accounts!
  25. blocked_domain_accounts.without_silenced.in_batches.update_all(silenced_at: @domain_block.created_at)
  26. end
  27. def suspend_accounts!
  28. blocked_domain_accounts.without_suspended.in_batches.update_all(suspended_at: @domain_block.created_at, suspension_origin: :local)
  29. blocked_domain_accounts.where(suspended_at: @domain_block.created_at).reorder(nil).find_each do |account|
  30. DeleteAccountService.new.call(account, reserve_username: true, suspended_at: @domain_block.created_at)
  31. end
  32. end
  33. def blocked_domain
  34. domain_block.domain
  35. end
  36. def blocked_domain_accounts
  37. Account.by_domain_and_subdomains(blocked_domain)
  38. end
  39. end