2016-11-15 07:56:29 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-10-09 05:48:43 -07:00
|
|
|
class BlockDomainService < BaseService
|
2017-04-26 11:09:01 -07:00
|
|
|
attr_reader :domain_block
|
|
|
|
|
2017-04-03 09:55:06 -07:00
|
|
|
def call(domain_block)
|
2017-04-26 11:09:01 -07:00
|
|
|
@domain_block = domain_block
|
|
|
|
process_domain_block
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def process_domain_block
|
2017-04-03 09:55:06 -07:00
|
|
|
if domain_block.silence?
|
2017-04-26 11:09:01 -07:00
|
|
|
silence_accounts!
|
2017-01-23 08:38:38 -08:00
|
|
|
else
|
2017-04-26 11:09:01 -07:00
|
|
|
suspend_accounts!
|
2017-04-16 03:51:30 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-26 11:09:01 -07:00
|
|
|
def silence_accounts!
|
|
|
|
blocked_domain_accounts.update_all(silenced: true)
|
|
|
|
clear_media! if domain_block.reject_media?
|
|
|
|
end
|
2017-04-16 03:51:30 -07:00
|
|
|
|
2017-04-26 11:09:01 -07:00
|
|
|
def clear_media!
|
|
|
|
clear_account_images
|
|
|
|
clear_account_attachments
|
|
|
|
end
|
|
|
|
|
|
|
|
def suspend_accounts!
|
|
|
|
blocked_domain_accounts.where(suspended: false).find_each do |account|
|
|
|
|
account.subscription(api_subscription_url(account.id)).unsubscribe if account.subscribed?
|
|
|
|
SuspendAccountService.new.call(account)
|
|
|
|
end
|
2017-04-16 03:51:30 -07:00
|
|
|
end
|
|
|
|
|
2017-04-26 11:09:01 -07:00
|
|
|
def clear_account_images
|
|
|
|
blocked_domain_accounts.find_each do |account|
|
2017-04-16 03:51:30 -07:00
|
|
|
account.avatar.destroy
|
|
|
|
account.header.destroy
|
|
|
|
end
|
2017-04-26 11:09:01 -07:00
|
|
|
end
|
2017-04-16 03:51:30 -07:00
|
|
|
|
2017-04-26 11:09:01 -07:00
|
|
|
def clear_account_attachments
|
|
|
|
media_from_blocked_domain.find_each do |attachment|
|
2017-04-16 03:51:30 -07:00
|
|
|
attachment.file.destroy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-26 11:09:01 -07:00
|
|
|
def blocked_domain
|
|
|
|
domain_block.domain
|
|
|
|
end
|
|
|
|
|
|
|
|
def blocked_domain_accounts
|
|
|
|
Account.where(domain: blocked_domain)
|
|
|
|
end
|
|
|
|
|
|
|
|
def media_from_blocked_domain
|
|
|
|
MediaAttachment.where(account: blocked_domain_accounts).reorder(nil)
|
2016-10-09 05:48:43 -07:00
|
|
|
end
|
|
|
|
end
|