2016-11-15 10:56:29 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-10-09 08:48:43 -04:00
|
|
|
class BlockDomainService < BaseService
|
2017-04-26 14:09:01 -04:00
|
|
|
attr_reader :domain_block
|
|
|
|
|
2019-08-07 14:20:23 -04:00
|
|
|
def call(domain_block, update = false)
|
2017-04-26 14:09:01 -04:00
|
|
|
@domain_block = domain_block
|
2024-03-20 11:37:21 -04:00
|
|
|
@domain_block_event = nil
|
|
|
|
|
2018-03-08 00:59:42 -05:00
|
|
|
process_domain_block!
|
2019-08-07 14:20:23 -04:00
|
|
|
process_retroactive_updates! if update
|
2024-03-20 11:37:21 -04:00
|
|
|
notify_of_severed_relationships!
|
2017-04-26 14:09:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-08-07 14:20:23 -04: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?
|
2020-11-07 18:28:39 -05:00
|
|
|
scope.where(suspended_at: domain_block.created_at).in_batches.update_all(suspended_at: nil, suspension_origin: nil) unless domain_block.suspend?
|
2019-08-07 14:20:23 -04:00
|
|
|
end
|
|
|
|
|
2018-03-08 00:59:42 -05:00
|
|
|
def process_domain_block!
|
2017-04-03 12:55:06 -04:00
|
|
|
if domain_block.silence?
|
2017-04-26 14:09:01 -04:00
|
|
|
silence_accounts!
|
2017-07-24 08:26:55 -04:00
|
|
|
elsif domain_block.suspend?
|
2017-04-26 14:09:01 -04:00
|
|
|
suspend_accounts!
|
2017-04-16 06:51:30 -04:00
|
|
|
end
|
2019-11-21 05:36:16 -05:00
|
|
|
|
2020-06-09 04:32:00 -04:00
|
|
|
DomainClearMediaWorker.perform_async(domain_block.id) if domain_block.reject_media?
|
2018-03-08 00:59:42 -05:00
|
|
|
end
|
|
|
|
|
2017-04-26 14:09:01 -04:00
|
|
|
def silence_accounts!
|
2019-05-14 13:05:02 -04:00
|
|
|
blocked_domain_accounts.without_silenced.in_batches.update_all(silenced_at: @domain_block.created_at)
|
2017-04-26 14:09:01 -04:00
|
|
|
end
|
2017-04-16 06:51:30 -04:00
|
|
|
|
2017-04-26 14:09:01 -04:00
|
|
|
def suspend_accounts!
|
2020-11-07 18:28:39 -05:00
|
|
|
blocked_domain_accounts.without_suspended.in_batches.update_all(suspended_at: @domain_block.created_at, suspension_origin: :local)
|
|
|
|
|
2020-06-09 04:32:00 -04:00
|
|
|
blocked_domain_accounts.where(suspended_at: @domain_block.created_at).reorder(nil).find_each do |account|
|
2024-03-20 11:37:21 -04:00
|
|
|
DeleteAccountService.new.call(account, reserve_username: true, suspended_at: @domain_block.created_at, relationship_severance_event: domain_block_event)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def notify_of_severed_relationships!
|
|
|
|
return if @domain_block_event.nil?
|
|
|
|
|
|
|
|
# TODO: check how efficient that query is, also check `push_bulk`/`perform_bulk`
|
|
|
|
@domain_block_event.affected_local_accounts.reorder(nil).find_each do |account|
|
|
|
|
event = AccountRelationshipSeveranceEvent.create!(account: account, relationship_severance_event: @domain_block_event)
|
|
|
|
LocalNotificationWorker.perform_async(account.id, event.id, 'AccountRelationshipSeveranceEvent', 'severed_relationships')
|
2017-04-26 14:09:01 -04:00
|
|
|
end
|
2017-04-16 06:51:30 -04:00
|
|
|
end
|
|
|
|
|
2017-04-26 14:09:01 -04:00
|
|
|
def blocked_domain
|
|
|
|
domain_block.domain
|
|
|
|
end
|
|
|
|
|
2024-03-20 11:37:21 -04:00
|
|
|
def domain_block_event
|
|
|
|
@domain_block_event ||= RelationshipSeveranceEvent.create!(type: :domain_block, target_name: blocked_domain)
|
|
|
|
end
|
|
|
|
|
2017-04-26 14:09:01 -04:00
|
|
|
def blocked_domain_accounts
|
2019-06-21 18:13:10 -04:00
|
|
|
Account.by_domain_and_subdomains(blocked_domain)
|
2017-04-26 14:09:01 -04:00
|
|
|
end
|
2016-10-09 08:48:43 -04:00
|
|
|
end
|