2016-11-16 02:56:29 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-10-09 23:48:43 +11:00
|
|
|
class BlockDomainService < BaseService
|
2017-04-27 04:09:01 +10:00
|
|
|
attr_reader :domain_block
|
|
|
|
|
2017-04-04 02:55:06 +10:00
|
|
|
def call(domain_block)
|
2017-04-27 04:09:01 +10:00
|
|
|
@domain_block = domain_block
|
|
|
|
process_domain_block
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def process_domain_block
|
2017-07-24 22:26:55 +10:00
|
|
|
clear_media! if domain_block.reject_media?
|
2017-04-04 02:55:06 +10:00
|
|
|
if domain_block.silence?
|
2017-04-27 04:09:01 +10:00
|
|
|
silence_accounts!
|
2017-07-24 22:26:55 +10:00
|
|
|
elsif domain_block.suspend?
|
2017-04-27 04:09:01 +10:00
|
|
|
suspend_accounts!
|
2017-04-16 20:51:30 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-27 04:09:01 +10:00
|
|
|
def silence_accounts!
|
2017-05-07 01:03:34 +10:00
|
|
|
blocked_domain_accounts.in_batches.update_all(silenced: true)
|
2017-04-27 04:09:01 +10:00
|
|
|
end
|
2017-04-16 20:51:30 +10:00
|
|
|
|
2017-04-27 04:09:01 +10:00
|
|
|
def clear_media!
|
|
|
|
clear_account_images
|
|
|
|
clear_account_attachments
|
2017-09-19 11:52:38 +10:00
|
|
|
clear_emojos
|
2017-04-27 04:09:01 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
def suspend_accounts!
|
|
|
|
blocked_domain_accounts.where(suspended: false).find_each do |account|
|
2017-08-22 01:32:41 +10:00
|
|
|
UnsubscribeService.new.call(account) if account.subscribed?
|
2017-04-27 04:09:01 +10:00
|
|
|
SuspendAccountService.new.call(account)
|
|
|
|
end
|
2017-04-16 20:51:30 +10:00
|
|
|
end
|
|
|
|
|
2017-04-27 04:09:01 +10:00
|
|
|
def clear_account_images
|
|
|
|
blocked_domain_accounts.find_each do |account|
|
2017-04-16 20:51:30 +10:00
|
|
|
account.avatar.destroy
|
|
|
|
account.header.destroy
|
2017-04-29 10:44:03 +10:00
|
|
|
account.save
|
2017-04-16 20:51:30 +10:00
|
|
|
end
|
2017-04-27 04:09:01 +10:00
|
|
|
end
|
2017-04-16 20:51:30 +10:00
|
|
|
|
2017-04-27 04:09:01 +10:00
|
|
|
def clear_account_attachments
|
|
|
|
media_from_blocked_domain.find_each do |attachment|
|
2017-04-16 20:51:30 +10:00
|
|
|
attachment.file.destroy
|
2017-04-29 10:44:03 +10:00
|
|
|
attachment.type = :unknown
|
|
|
|
attachment.save
|
2017-04-16 20:51:30 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-19 11:52:38 +10:00
|
|
|
def clear_emojos
|
|
|
|
emojis_from_blocked_domains.destroy_all
|
|
|
|
end
|
|
|
|
|
2017-04-27 04:09:01 +10:00
|
|
|
def blocked_domain
|
|
|
|
domain_block.domain
|
|
|
|
end
|
|
|
|
|
|
|
|
def blocked_domain_accounts
|
|
|
|
Account.where(domain: blocked_domain)
|
|
|
|
end
|
|
|
|
|
|
|
|
def media_from_blocked_domain
|
2017-05-20 23:13:51 +10:00
|
|
|
MediaAttachment.joins(:account).merge(blocked_domain_accounts).reorder(nil)
|
2016-10-09 23:48:43 +11:00
|
|
|
end
|
2017-09-19 11:52:38 +10:00
|
|
|
|
|
|
|
def emojis_from_blocked_domains
|
|
|
|
CustomEmoji.where(domain: blocked_domain)
|
|
|
|
end
|
2016-10-09 23:48:43 +11:00
|
|
|
end
|