about summary refs log tree commit diff
path: root/app/services/after_block_service.rb
blob: 432ba65e67758795b593827af9506ed1e74f19b7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# frozen_string_literal: true

class AfterBlockService < BaseService
  def call(account, target_account)
    @account        = account
    @target_account = target_account

    clear_home_feed!
    clear_notifications!
    clear_conversations!
    unlink_replies!
    unlink_mentions!
  end

  private

  def clear_home_feed!
    FeedManager.instance.clear_from_timeline(@account, @target_account)
  end

  def clear_conversations!
    AccountConversation.where(account: @account).where('? = ANY(participant_account_ids)', @target_account.id).in_batches.destroy_all
  end

  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