about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--app/services/after_block_service.rb14
-rw-r--r--db/migrate/20200823002835_unlink_blocked_replies.rb28
-rw-r--r--db/schema.rb2
3 files changed, 43 insertions, 1 deletions
diff --git a/app/services/after_block_service.rb b/app/services/after_block_service.rb
index 2a0e10a79..432ba65e6 100644
--- a/app/services/after_block_service.rb
+++ b/app/services/after_block_service.rb
@@ -8,6 +8,8 @@ class AfterBlockService < BaseService
     clear_home_feed!
     clear_notifications!
     clear_conversations!
+    unlink_replies!
+    unlink_mentions!
   end
 
   private
@@ -23,4 +25,16 @@ class AfterBlockService < BaseService
   def clear_notifications!
     Notification.where(account: @account).where(from_account: @target_account).in_batches.delete_all
   end
+
+  def unlink_replies!
+    @target_account.statuses.where(in_reply_to_account_id: @account.id)
+                   .or(@account.statuses.where(in_reply_to_account_id: @target_account.id))
+                   .in_batches.update_all(in_reply_to_account_id: nil)
+  end
+
+  def unlink_mentions!
+    @account.mentions.where(account_id: @target_account.id)
+            .or(@target_account.mentions.where(account_id: @account.id))
+            .in_batches.destroy_all
+  end
 end
diff --git a/db/migrate/20200823002835_unlink_blocked_replies.rb b/db/migrate/20200823002835_unlink_blocked_replies.rb
new file mode 100644
index 000000000..6968fc93f
--- /dev/null
+++ b/db/migrate/20200823002835_unlink_blocked_replies.rb
@@ -0,0 +1,28 @@
+class UnlinkBlockedReplies < ActiveRecord::Migration[5.2]
+  def up
+    Block.find_each do |block|
+      next if block.account.nil? || block.target_account.nil?
+
+      unlink_replies!(block.account, block.target_account)
+      unlink_mentions!(block.account, block.target_account)
+    end
+  end
+
+  def down
+    nil
+  end
+
+  private
+
+  def unlink_replies!(account, target_account)
+    target_account.statuses.where(in_reply_to_account_id: account.id)
+      .or(account.statuses.where(in_reply_to_account_id: target_account.id))
+      .in_batches.update_all(in_reply_to_account_id: nil)
+  end
+
+  def unlink_mentions!(account, target_account)
+    account.mentions.where(account_id: target_account.id)
+      .or(target_account.mentions.where(account_id: account.id))
+      .in_batches.destroy_all
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 498f2e052..2aa5f6dee 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 2020_08_22_054516) do
+ActiveRecord::Schema.define(version: 2020_08_23_002835) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"