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
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user