diff options
author | ThibG <thib@sitedethib.com> | 2020-07-01 13:51:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-01 13:51:15 +0200 |
commit | 35cedc922ced6502f18b11353df661cf61c8ae2f (patch) | |
tree | 10c12d29a781dc398df9a98e7ec4a40183975cc8 /app/workers | |
parent | 411bf188bbb9acb48b7bb1a14066f4975e036940 (diff) |
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
Diffstat (limited to 'app/workers')
-rw-r--r-- | app/workers/activitypub/move_distribution_worker.rb | 2 | ||||
-rw-r--r-- | app/workers/move_worker.rb | 27 |
2 files changed, 28 insertions, 1 deletions
diff --git a/app/workers/activitypub/move_distribution_worker.rb b/app/workers/activitypub/move_distribution_worker.rb index bf1c0e7ae..65c5c0d1c 100644 --- a/app/workers/activitypub/move_distribution_worker.rb +++ b/app/workers/activitypub/move_distribution_worker.rb @@ -24,7 +24,7 @@ class ActivityPub::MoveDistributionWorker private def inboxes - @inboxes ||= @migration.account.followers.inboxes + @inboxes ||= (@migration.account.followers.inboxes + @migration.account.blocked_by.inboxes).uniq end def signed_payload 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 |