The code powering m.abunchtell.com https://m.abunchtell.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

43 lines
1.3 KiB

  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: domain_blocks
  5. #
  6. # id :bigint(8) not null, primary key
  7. # domain :string default(""), not null
  8. # created_at :datetime not null
  9. # updated_at :datetime not null
  10. # severity :integer default("silence")
  11. # reject_media :boolean default(FALSE), not null
  12. # reject_reports :boolean default(FALSE), not null
  13. #
  14. class DomainBlock < ApplicationRecord
  15. include DomainNormalizable
  16. enum severity: [:silence, :suspend, :noop]
  17. validates :domain, presence: true, uniqueness: true
  18. has_many :accounts, foreign_key: :domain, primary_key: :domain
  19. delegate :count, to: :accounts, prefix: true
  20. scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) }
  21. def self.blocked?(domain)
  22. where(domain: domain, severity: :suspend).exists?
  23. end
  24. def stricter_than?(other_block)
  25. return true if suspend?
  26. return false if other_block.suspend? && (silence? || noop?)
  27. return false if other_block.silence? && noop?
  28. (reject_media || !other_block.reject_media) && (reject_reports || !other_block.reject_reports)
  29. end
  30. def affected_accounts_count
  31. scope = suspend? ? accounts.where(suspended_at: created_at) : accounts.where(silenced_at: created_at)
  32. scope.count
  33. end
  34. end