From 35cedc922ced6502f18b11353df661cf61c8ae2f Mon Sep 17 00:00:00 2001 From: ThibG Date: Wed, 1 Jul 2020 13:51:15 +0200 Subject: Change move handler to carry blocks over (#14144) * Change move handler to carry blocks and mutes over When user A blocks user B and B moves to a new account C, make A block C accordingly. Note that it only works if A's instance is aware of the Move, that is, if B is on A's instance or has followers there. * Also notify instances with known people blocking you when moving * Add automatic account notes when blocking/muting an account that had no note --- app/workers/move_worker.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'app/workers/move_worker.rb') diff --git a/app/workers/move_worker.rb b/app/workers/move_worker.rb index 4d76461b0..39e321316 100644 --- a/app/workers/move_worker.rb +++ b/app/workers/move_worker.rb @@ -14,6 +14,8 @@ class MoveWorker end copy_account_notes! + carry_blocks_over! + carry_mutes_over! rescue ActiveRecord::RecordNotFound true end @@ -51,4 +53,29 @@ class MoveWorker end end end + + def carry_blocks_over! + @source_account.blocked_by_relationships.where(account: Account.local).find_each do |block| + unless block.account.blocking?(@target_account) || block.account.following?(@target_account) + BlockService.new.call(block.account, @target_account) + add_account_note_if_needed!(block.account, 'move_handler.carry_blocks_over_text') + end + end + end + + def carry_mutes_over! + @source_account.muted_by_relationships.where(account: Account.local).find_each do |mute| + MuteService.new.call(mute.account, @target_account, notifications: mute.hide_notifications) unless mute.account.muting?(@target_account) || mute.account.following?(@target_account) + add_account_note_if_needed!(mute.account, 'move_handler.carry_mutes_over_text') + end + end + + def add_account_note_if_needed!(account, id) + unless AccountNote.where(account: account, target_account: @target_account).exists? + text = I18n.with_locale(account.user.locale || I18n.default_locale) do + I18n.t(id, acct: @source_account.acct) + end + AccountNote.create!(account: account, target_account: @target_account, comment: text) + end + end end -- cgit