about summary refs log tree commit diff
path: root/app/services/block_domain_service.rb
blob: 9518b1fcf2860e855161a6051f70b7cc8f239530 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# frozen_string_literal: true

class BlockDomainService < BaseService
  def call(domain, severity)
    DomainBlock.where(domain: domain).first_or_create!(domain: domain, severity: severity)

    if severity == :silence
      Account.where(domain: domain).update_all(silenced: true)
    else
      Account.where(domain: domain).find_each do |account|
        account.subscription(api_subscription_url(account.id)).unsubscribe if account.subscribed?
        SuspendAccountService.new.call(account)
      end
    end
  end
end