1 # frozen_string_literal: true
 
   3 # == Schema Information
 
   5 # Table name: user_mutes
 
   7 #  id         :bigint           not null, primary key
 
   8 #  owner_id   :bigint           not null
 
   9 #  subject_id :bigint           not null
 
  10 #  created_at :datetime         not null
 
  11 #  updated_at :datetime         not null
 
  15 #  index_user_mutes_on_owner_id_and_subject_id  (owner_id,subject_id) UNIQUE
 
  19 #  fk_rails_...  (owner_id => users.id)
 
  20 #  fk_rails_...  (subject_id => users.id)
 
  22 class UserMute < ApplicationRecord
 
  23   belongs_to :owner, :class_name => "User"
 
  24   belongs_to :subject, :class_name => "User"
 
  26   validates :subject, :uniqueness => { :scope => :owner_id, :message => :is_already_muted }
 
  28   def self.active?(owner:, subject:)
 
  29     !subject.administrator? &&
 
  30       !subject.moderator? &&