about summary refs log tree commit diff
path: root/app/services/defederate_account_serivice.rb
blob: 5d9cc1597898b49fb1aaf0e0125f441f52f199b1 (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
# frozen_string_literal: true

class DefederateAccountService < BaseService
  include Payloadable

  def call(account, domains)
    @account = account
    @domains = domains

    return if account.blank? || !account.local? || domains.blank?

    distribute_delete_actor!
  end

  private

  def distribute_delete_actor!
    ActivityPub::DeliveryWorker.push_bulk(delivery_inboxes) do |inbox_url|
      [delete_actor_json, @account.id, inbox_url]
    end

    ActivityPub::LowPriorityDeliveryWorker.push_bulk(low_priority_delivery_inboxes) do |inbox_url|
      [delete_actor_json, @account.id, inbox_url]
    end
  end

  def delete_actor_json
    @delete_actor_json ||= Oj.dump(serialize_payload(@account, ActivityPub::DeleteActorSerializer, signer: @account))
  end

  def delivery_inboxes
    @delivery_inboxes ||= @account.followers.where(domain: @domains).inboxes
  end

  def low_priority_delivery_inboxes
    Account.where(domain: @domains).inboxes - delivery_inboxes
  end
end