block_domain_service.rb 524 Bytes
Newer Older
1
2
# frozen_string_literal: true

Eugen Rochko's avatar
Eugen Rochko committed
3
class BlockDomainService < BaseService
4
5
  def call(domain, severity)
    DomainBlock.where(domain: domain).first_or_create!(domain: domain, severity: severity)
Eugen Rochko's avatar
Eugen Rochko committed
6

7
8
9
10
11
12
    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)
Eugen Rochko's avatar
Eugen Rochko committed
13
14
15
16
      end
    end
  end
end