Merge remote-tracking branch 'parent/main' into upstream-20240326
This commit is contained in:
commit
6c9b221cb2
263 changed files with 4628 additions and 1518 deletions
|
@ -9,18 +9,21 @@ class AfterBlockDomainFromAccountService < BaseService
|
|||
def call(account, domain)
|
||||
@account = account
|
||||
@domain = domain
|
||||
@domain_block_event = nil
|
||||
|
||||
clear_notifications!
|
||||
remove_follows!
|
||||
reject_existing_followers!
|
||||
reject_pending_follow_requests!
|
||||
notify_of_severed_relationships!
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def remove_follows!
|
||||
@account.active_relationships.where(target_account: Account.where(domain: @domain)).includes(:target_account).reorder(nil).find_each do |follow|
|
||||
UnfollowService.new.call(@account, follow.target_account)
|
||||
@account.active_relationships.where(target_account: Account.where(domain: @domain)).includes(:target_account).reorder(nil).in_batches do |follows|
|
||||
domain_block_event.import_from_active_follows!(follows)
|
||||
follows.each { |follow| UnfollowService.new.call(@account, follow.target_account) }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -29,8 +32,9 @@ class AfterBlockDomainFromAccountService < BaseService
|
|||
end
|
||||
|
||||
def reject_existing_followers!
|
||||
@account.passive_relationships.where(account: Account.where(domain: @domain)).includes(:account).reorder(nil).find_each do |follow|
|
||||
reject_follow!(follow)
|
||||
@account.passive_relationships.where(account: Account.where(domain: @domain)).includes(:account).reorder(nil).in_batches do |follows|
|
||||
domain_block_event.import_from_passive_follows!(follows)
|
||||
follows.each { |follow| reject_follow!(follow) }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -47,4 +51,15 @@ class AfterBlockDomainFromAccountService < BaseService
|
|||
|
||||
ActivityPub::DeliveryWorker.perform_async(Oj.dump(serialize_payload(follow, ActivityPub::RejectFollowSerializer)), @account.id, follow.account.inbox_url)
|
||||
end
|
||||
|
||||
def notify_of_severed_relationships!
|
||||
return if @domain_block_event.nil?
|
||||
|
||||
event = AccountRelationshipSeveranceEvent.create!(account: @account, relationship_severance_event: @domain_block_event)
|
||||
LocalNotificationWorker.perform_async(@account.id, event.id, 'AccountRelationshipSeveranceEvent', 'severed_relationships')
|
||||
end
|
||||
|
||||
def domain_block_event
|
||||
@domain_block_event ||= RelationshipSeveranceEvent.create!(type: :user_domain_block, target_name: @domain)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,8 +5,11 @@ class BlockDomainService < BaseService
|
|||
|
||||
def call(domain_block, update = false)
|
||||
@domain_block = domain_block
|
||||
@domain_block_event = nil
|
||||
|
||||
process_domain_block!
|
||||
process_retroactive_updates! if update
|
||||
notify_of_severed_relationships!
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -40,7 +43,17 @@ class BlockDomainService < BaseService
|
|||
blocked_domain_accounts.without_suspended.in_batches.update_all(suspended_at: @domain_block.created_at, suspension_origin: :local)
|
||||
|
||||
blocked_domain_accounts.where(suspended_at: @domain_block.created_at).reorder(nil).find_each do |account|
|
||||
DeleteAccountService.new.call(account, reserve_username: true, suspended_at: @domain_block.created_at)
|
||||
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')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -52,6 +65,10 @@ class BlockDomainService < BaseService
|
|||
domain_block.domain
|
||||
end
|
||||
|
||||
def domain_block_event
|
||||
@domain_block_event ||= RelationshipSeveranceEvent.create!(type: :domain_block, target_name: blocked_domain)
|
||||
end
|
||||
|
||||
def blocked_domain_accounts
|
||||
Account.by_domain_and_subdomains(blocked_domain)
|
||||
end
|
||||
|
|
|
@ -72,6 +72,8 @@ class DeleteAccountService < BaseService
|
|||
reports
|
||||
targeted_moderation_notes
|
||||
targeted_reports
|
||||
severed_relationships
|
||||
remote_severed_relationships
|
||||
).freeze
|
||||
|
||||
# Suspend or remove an account and remove as much of its data
|
||||
|
@ -86,6 +88,7 @@ class DeleteAccountService < BaseService
|
|||
# @option [Boolean] :skip_side_effects Side effects are ActivityPub and streaming API payloads
|
||||
# @option [Boolean] :skip_activitypub Skip sending ActivityPub payloads. Implied by :skip_side_effects
|
||||
# @option [Time] :suspended_at Only applicable when :reserve_username is true
|
||||
# @option [RelationshipSeveranceEvent] :relationship_severance_event Event used to record severed relationships not initiated by the user
|
||||
def call(account, **options)
|
||||
@account = account
|
||||
@options = { reserve_username: true, reserve_email: true }.merge(options)
|
||||
|
@ -98,6 +101,7 @@ class DeleteAccountService < BaseService
|
|||
|
||||
@options[:skip_activitypub] = true if @options[:skip_side_effects]
|
||||
|
||||
record_severed_relationships!
|
||||
distribute_activities!
|
||||
purge_content!
|
||||
fulfill_deletion_request!
|
||||
|
@ -198,6 +202,7 @@ class DeleteAccountService < BaseService
|
|||
# polymorphically associated notifications generated by this account
|
||||
|
||||
Notification.where(from_account: @account).in_batches.delete_all
|
||||
NotificationRequest.where(from_account: @account).in_batches.delete_all
|
||||
end
|
||||
|
||||
def purge_favourites!
|
||||
|
@ -294,6 +299,20 @@ class DeleteAccountService < BaseService
|
|||
end
|
||||
end
|
||||
|
||||
def record_severed_relationships!
|
||||
return if relationship_severance_event.nil?
|
||||
|
||||
@account.active_relationships.in_batches do |follows|
|
||||
# NOTE: these follows are passive with regards to the local accounts
|
||||
relationship_severance_event.import_from_passive_follows!(follows)
|
||||
end
|
||||
|
||||
@account.passive_relationships.in_batches do |follows|
|
||||
# NOTE: these follows are active with regards to the local accounts
|
||||
relationship_severance_event.import_from_active_follows!(follows)
|
||||
end
|
||||
end
|
||||
|
||||
def delete_actor_json
|
||||
@delete_actor_json ||= Oj.dump(serialize_payload(@account, ActivityPub::DeleteActorSerializer, signer: @account, always_sign: true))
|
||||
end
|
||||
|
@ -333,4 +352,8 @@ class DeleteAccountService < BaseService
|
|||
def skip_activitypub?
|
||||
@options[:skip_activitypub]
|
||||
end
|
||||
|
||||
def relationship_severance_event
|
||||
@options[:relationship_severance_event]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,6 +13,8 @@ class NotifyService < BaseService
|
|||
status
|
||||
list_status
|
||||
warning
|
||||
# TODO: this probably warrants an email notification
|
||||
severed_relationships
|
||||
).freeze
|
||||
|
||||
class DismissCondition
|
||||
|
@ -24,7 +26,7 @@ class NotifyService < BaseService
|
|||
|
||||
def dismiss?
|
||||
blocked = @recipient.unavailable?
|
||||
blocked ||= from_self? && @notification.type != :poll
|
||||
blocked ||= from_self? && @notification.type != :poll && @notification.type != :severed_relationships
|
||||
|
||||
return blocked if message? && from_staff?
|
||||
|
||||
|
|
|
@ -2,10 +2,26 @@
|
|||
|
||||
class PurgeDomainService < BaseService
|
||||
def call(domain)
|
||||
Account.remote.where(domain: domain).reorder(nil).find_each do |account|
|
||||
DeleteAccountService.new.call(account, reserve_username: false, skip_side_effects: true)
|
||||
end
|
||||
CustomEmoji.remote.where(domain: domain).reorder(nil).find_each(&:destroy)
|
||||
@domain = domain
|
||||
|
||||
purge_relationship_severance_events!
|
||||
purge_accounts!
|
||||
purge_emojis!
|
||||
|
||||
Instance.refresh
|
||||
end
|
||||
|
||||
def purge_relationship_severance_events!
|
||||
RelationshipSeveranceEvent.where(type: [:domain_block, :user_domain_block], target_name: @domain).in_batches.update_all(purged: true)
|
||||
end
|
||||
|
||||
def purge_accounts!
|
||||
Account.remote.where(domain: @domain).reorder(nil).find_each do |account|
|
||||
DeleteAccountService.new.call(account, reserve_username: false, skip_side_effects: true)
|
||||
end
|
||||
end
|
||||
|
||||
def purge_emojis!
|
||||
CustomEmoji.remote.where(domain: @domain).reorder(nil).find_each(&:destroy)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue