diff options
Diffstat (limited to 'app/services/after_block_service.rb')
-rw-r--r-- | app/services/after_block_service.rb | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/app/services/after_block_service.rb b/app/services/after_block_service.rb index 314919df8..36f891988 100644 --- a/app/services/after_block_service.rb +++ b/app/services/after_block_service.rb @@ -1,13 +1,18 @@ # frozen_string_literal: true class AfterBlockService < BaseService - def call(account, target_account) + def call(account, target_account, defederate: true) @account = account @target_account = target_account clear_home_feed! clear_notifications! clear_conversations! + + return unless defederate + + defederate_interactions! + unlink_interactions! end private @@ -23,4 +28,27 @@ class AfterBlockService < BaseService def clear_notifications! Notification.where(account: @account).where(from_account: @target_account).in_batches.delete_all end + + def unlink_interactions! + @target_account.statuses.where(in_reply_to_account_id: @account.id).in_batches.update_all(in_reply_to_account_id: nil) + @target_account.mentions.where(account_id: @account.id).in_batches.destroy_all + end + + def defederate_interactions! + defederate_statuses!(@account.statuses.where(in_reply_to_account_id: @target_account.id)) + defederate_statuses!(@account.statuses.joins(:mentions).where(mentions: { account_id: @target_account.id })) + defederate_statuses!(@account.statuses.joins(:reblog).where(reblogs_statuses: { account_id: @target_account.id })) + defederate_favourites! + end + + def defederate_statuses!(statuses) + statuses.find_each { |status| RemovalWorker.perform_async(status.id, unpublish: true, blocking: @target_account.id) } + end + + def defederate_favourites! + favourites = @account.favourites.joins(:status).where(statuses: { account_id: @target_account.id }) + favourites.pluck(:status_id).each do |status_id| + UnfavouriteWorker.perform_async(@account.id, status_id) + end + end end |