class AnnonceMessage < ActiveRecord::Base
  belongs_to :annonce
  belongs_to :expediteur, :class_name => "AnnonceAccount"
  belongs_to :destinataire, :class_name => "AnnonceAccount"
  has_one :ip_history, :as => :element
  validates :name, :presence => true, :unless => :expediteur_s?
  #validates :expediteur_mail, :presence => true
  #validates :title, :presence => true
  validates :message, :presence => true
  acts_as_tree
  
  def expediteur_s?
    true if self.expediteur
  end
  
  def not_blocked
    if (!self.expediteur or self.expediteur.not_blocked)
      true
      
    else
      
      false
    end
  end
end
