lib/blather/stanza/message.rb in sprsquish-blather-0.3.4 vs lib/blather/stanza/message.rb in sprsquish-blather-0.4.0

- old
+ new

@@ -6,17 +6,29 @@ class Message < Stanza VALID_TYPES = [:chat, :error, :groupchat, :headline, :normal] register :message - def initialize(to = nil, body = nil, type = :chat) - super() - self.to = to - self.type = type - self.body = body + def self.import(node) + klass = nil + node.children.each { |e| break if klass = class_from_registration(e.element_name, (e.namespace.href if e.namespace)) } + + if klass && klass != self + klass.import(node) + else + new(node[:type]).inherit(node) + end end + def self.new(to = nil, body = nil, type = :chat) + node = super(:message) + node.to = to + node.type = type + node.body = body + node + end + VALID_TYPES.each do |valid_type| define_method("#{valid_type}?") { self.type == valid_type } end ## @@ -24,35 +36,12 @@ def type=(type) raise ArgumentError, "Invalid Type (#{type}), use: #{VALID_TYPES*' '}" if type && !VALID_TYPES.include?(type.to_sym) super end - def body=(body) - remove_child :body - self << XMPPNode.new('body', body) if body - end - - def body - content_from :body - end - - def subject=(subject) - remove_child :subject - self << XMPPNode.new('subject', subject) if subject - end - - def subject - content_from :subject - end - - def thread=(thread) - remove_child :thread - self << XMPPNode.new('thread', thread) if thread - end - - def thread - content_from :thread - end + content_attr_accessor :body + content_attr_accessor :subject + content_attr_accessor :thread end end #Stanza end \ No newline at end of file