Add notifications of severed relationships (#27511)
This commit is contained in:
parent
8a1423a474
commit
44bf7b8128
39 changed files with 781 additions and 54 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
|
||||
|
@ -37,7 +40,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
|
||||
|
||||
|
@ -45,6 +58,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
|
||||
|
|
|
@ -58,6 +58,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
|
||||
|
@ -72,6 +74,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)
|
||||
|
@ -84,6 +87,7 @@ class DeleteAccountService < BaseService
|
|||
|
||||
@options[:skip_activitypub] = true if @options[:skip_side_effects]
|
||||
|
||||
record_severed_relationships!
|
||||
distribute_activities!
|
||||
purge_content!
|
||||
fulfill_deletion_request!
|
||||
|
@ -266,6 +270,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
|
||||
|
@ -305,4 +323,8 @@ class DeleteAccountService < BaseService
|
|||
def skip_activitypub?
|
||||
@options[:skip_activitypub]
|
||||
end
|
||||
|
||||
def relationship_severance_event
|
||||
@options[:relationship_severance_event]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,6 +9,8 @@ class NotifyService < BaseService
|
|||
update
|
||||
poll
|
||||
status
|
||||
# TODO: this probably warrants an email notification
|
||||
severed_relationships
|
||||
).freeze
|
||||
|
||||
class DismissCondition
|
||||
|
@ -20,7 +22,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
|
||||
|
|
|
@ -8,6 +8,7 @@ class SuspendAccountService < BaseService
|
|||
def call(account)
|
||||
return unless account.suspended?
|
||||
|
||||
@relationship_severance_event = nil
|
||||
@account = account
|
||||
|
||||
reject_remote_follows!
|
||||
|
@ -15,6 +16,7 @@ class SuspendAccountService < BaseService
|
|||
unmerge_from_home_timelines!
|
||||
unmerge_from_list_timelines!
|
||||
privatize_media_attachments!
|
||||
notify_of_severed_relationships!
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -36,6 +38,8 @@ class SuspendAccountService < BaseService
|
|||
[Oj.dump(serialize_payload(follow, ActivityPub::RejectFollowSerializer)), follow.target_account_id, @account.inbox_url]
|
||||
end
|
||||
|
||||
relationship_severance_event.import_from_passive_follows!(follows)
|
||||
|
||||
follows.each(&:destroy)
|
||||
end
|
||||
end
|
||||
|
@ -101,7 +105,21 @@ class SuspendAccountService < BaseService
|
|||
end
|
||||
end
|
||||
|
||||
def notify_of_severed_relationships!
|
||||
return if @relationship_severance_event.nil?
|
||||
|
||||
# TODO: check how efficient that query is, also check `push_bulk`/`perform_bulk`
|
||||
@relationship_severance_event.affected_local_accounts.reorder(nil).find_each do |account|
|
||||
event = AccountRelationshipSeveranceEvent.create!(account: account, relationship_severance_event: @relationship_severance_event)
|
||||
LocalNotificationWorker.perform_async(account.id, event.id, 'AccountRelationshipSeveranceEvent', 'severed_relationships')
|
||||
end
|
||||
end
|
||||
|
||||
def signed_activity_json
|
||||
@signed_activity_json ||= Oj.dump(serialize_payload(@account, ActivityPub::UpdateSerializer, signer: @account))
|
||||
end
|
||||
|
||||
def relationship_severance_event
|
||||
@relationship_severance_event ||= RelationshipSeveranceEvent.create!(type: :account_suspension, target_name: @account.acct)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue