clear_domain_media_service.rb 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # frozen_string_literal: true
  2. class ClearDomainMediaService < BaseService
  3. attr_reader :domain_block
  4. def call(domain_block)
  5. @domain_block = domain_block
  6. clear_media! if domain_block.reject_media?
  7. end
  8. private
  9. def clear_media!
  10. clear_account_images!
  11. clear_account_attachments!
  12. clear_emojos!
  13. end
  14. def clear_account_images!
  15. blocked_domain_accounts.reorder(nil).find_in_batches do |accounts|
  16. AttachmentBatch.new(Account, accounts).clear
  17. end
  18. end
  19. def clear_account_attachments!
  20. media_from_blocked_domain.reorder(nil).find_in_batches do |attachments|
  21. AttachmentBatch.new(MediaAttachment, attachments).clear
  22. end
  23. end
  24. def clear_emojos!
  25. emojis_from_blocked_domains.find_in_batches do |custom_emojis|
  26. AttachmentBatch.new(CustomEmoji, custom_emojis).delete
  27. end
  28. end
  29. def blocked_domain
  30. domain_block.domain
  31. end
  32. def blocked_domain_accounts
  33. Account.by_domain_and_subdomains(blocked_domain)
  34. end
  35. def media_from_blocked_domain
  36. MediaAttachment.joins(:account).merge(blocked_domain_accounts)
  37. end
  38. def emojis_from_blocked_domains
  39. CustomEmoji.by_domain_and_subdomains(blocked_domain)
  40. end
  41. end