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
|
|
|
|
|
2019-08-08 04:20:23 +10:00
|
|
|
def call(domain_block, update = false)
|
2017-04-27 04:09:01 +10:00
|
|
|
@domain_block = domain_block
|
2018-03-08 16:59:42 +11:00
|
|
|
process_domain_block!
|
2019-08-08 04:20:23 +10:00
|
|
|
process_retroactive_updates! if update
|
2017-04-27 04:09:01 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-08-08 04:20:23 +10:00
|
|
|
def process_retroactive_updates!
|
|
|
|
# If the domain block severity has been changed, undo the appropriate limitations
|
|
|
|
scope = Account.by_domain_and_subdomains(domain_block.domain)
|
|
|
|
|
|
|
|
scope.where(silenced_at: domain_block.created_at).in_batches.update_all(silenced_at: nil) unless domain_block.silence?
|
|
|
|
scope.where(suspended_at: domain_block.created_at).in_batches.update_all(suspended_at: nil) unless domain_block.suspend?
|
|
|
|
end
|
|
|
|
|
2018-03-08 16:59:42 +11:00
|
|
|
def process_domain_block!
|
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
|
2019-11-21 21:36:16 +11:00
|
|
|
|
2020-06-09 18:32:00 +10:00
|
|
|
DomainClearMediaWorker.perform_async(domain_block.id) if domain_block.reject_media?
|
2018-03-08 16:59:42 +11:00
|
|
|
end
|
|
|
|
|
2017-04-27 04:09:01 +10:00
|
|
|
def silence_accounts!
|
2019-05-15 03:05:02 +10:00
|
|
|
blocked_domain_accounts.without_silenced.in_batches.update_all(silenced_at: @domain_block.created_at)
|
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 suspend_accounts!
|
2020-06-09 18:32:00 +10:00
|
|
|
blocked_domain_accounts.without_suspended.in_batches.update_all(suspended_at: @domain_block.created_at)
|
|
|
|
blocked_domain_accounts.where(suspended_at: @domain_block.created_at).reorder(nil).find_each do |account|
|
2019-09-12 00:32:44 +10:00
|
|
|
SuspendAccountService.new.call(account, reserve_username: true, suspended_at: @domain_block.created_at)
|
2017-04-27 04:09:01 +10:00
|
|
|
end
|
2017-04-16 20:51:30 +10:00
|
|
|
end
|
|
|
|
|
2017-04-27 04:09:01 +10:00
|
|
|
def blocked_domain
|
|
|
|
domain_block.domain
|
|
|
|
end
|
|
|
|
|
|
|
|
def blocked_domain_accounts
|
2019-06-22 08:13:10 +10:00
|
|
|
Account.by_domain_and_subdomains(blocked_domain)
|
2017-04-27 04:09:01 +10:00
|
|
|
end
|
2016-10-09 23:48:43 +11:00
|
|
|
end
|