闭社主体 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.

36 lines
980 B

  1. # frozen_string_literal: true
  2. class BlockDomainService < BaseService
  3. def call(domain_block)
  4. if domain_block.silence?
  5. silence_accounts!(domain_block.domain)
  6. clear_media!(domain_block.domain) if domain_block.reject_media?
  7. else
  8. suspend_accounts!(domain_block.domain)
  9. end
  10. end
  11. private
  12. def silence_accounts!(domain)
  13. Account.where(domain: domain).update_all(silenced: true)
  14. end
  15. def clear_media!(domain)
  16. Account.where(domain: domain).find_each do |account|
  17. account.avatar.destroy
  18. account.header.destroy
  19. end
  20. MediaAttachment.where(account: Account.where(domain: domain)).find_each do |attachment|
  21. attachment.file.destroy
  22. end
  23. end
  24. def suspend_accounts!(domain)
  25. Account.where(domain: domain).where(suspended: false).find_each do |account|
  26. account.subscription(api_subscription_url(account.id)).unsubscribe if account.subscribed?
  27. SuspendAccountService.new.call(account)
  28. end
  29. end
  30. end