Class Jabber::Message
In: lib/xmpp4r/message.rb
Parent: XMLStanza

The Message class manages the <message/> stanzas, which is used for all messaging communication.

Methods

body   body=   import   new   set_body   set_subject   set_thread   set_type   subject   subject=   thread   thread=   type   type=   typed_add   x  

Public Class methods

Create a new message from a stanza, by copying all attributes and children from it.

xmlstanza:[REXML::Element] Source
return:[Message] Result

[Source]

     # File lib/xmpp4r/message.rb, line 109
109:     def Message.import(xmlstanza)
110:       Message::new.import(xmlstanza)
111:     end

Create a new message

>to:a JID or a String object to send the message to.
>body:the message‘s body

[Source]

    # File lib/xmpp4r/message.rb, line 18
18:     def initialize(to = nil, body = nil)
19:       super("message")
20:       if not to.nil?
21:         set_to(to)
22:       end
23:       if !body.nil?
24:         add_element(REXML::Element::new("body").add_text(body))
25:       end
26:     end

Public Instance methods

Returns the message‘s body, or nil. This is the message‘s plain-text content.

[Source]

     # File lib/xmpp4r/message.rb, line 100
100:     def body
101:       first_element_text('body')
102:     end

Sets the message‘s body

b:[String] body to set

[Source]

     # File lib/xmpp4r/message.rb, line 117
117:     def body=(b)
118:       replace_element_text('body', b)
119:     end

Sets the message‘s body

b:[String] body to set
return:[REXML::Element] self for chaining

[Source]

     # File lib/xmpp4r/message.rb, line 126
126:     def set_body(b)
127:       self.body = b
128:       self
129:     end

sets the message‘s subject

s:[String] subject to set
return:[REXML::Element] self for chaining

[Source]

     # File lib/xmpp4r/message.rb, line 144
144:     def set_subject(s)
145:       self.subject = s
146:       self
147:     end

gets the message‘s thread (chaining-friendly) Please note that this are not [Thread] but a [String]-Identifier to track conversations

s:[String] thread to set

[Source]

     # File lib/xmpp4r/message.rb, line 167
167:     def set_thread(s)
168:       self.thread = s
169:       self
170:     end

Set the type of the Message stanza (chaining-friendly)

v:[Symbol] or nil

[Source]

    # File lib/xmpp4r/message.rb, line 79
79:     def set_type(v)
80:       self.type = v
81:       self
82:     end

Returns the message‘s subject, or nil

[Source]

     # File lib/xmpp4r/message.rb, line 151
151:     def subject
152:       first_element_text('subject')
153:     end

sets the message‘s subject

s:[String] subject to set

[Source]

     # File lib/xmpp4r/message.rb, line 135
135:     def subject=(s)
136:       replace_element_text('subject', s)
137:     end

Returns the message‘s thread, or nil

[Source]

     # File lib/xmpp4r/message.rb, line 174
174:     def thread
175:       first_element_text('thread')
176:     end

sets the message‘s thread

s:[String] thread to set

[Source]

     # File lib/xmpp4r/message.rb, line 158
158:     def thread=(s)
159:       delete_elements('thread')
160:       replace_element_text('thread', s) unless s.nil?
161:     end

Get the type of the Message stanza

The following Symbols are allowed:

  • :chat
  • :error
  • :groupchat
  • :headline
  • :normal
result:[Symbol] or nil

[Source]

    # File lib/xmpp4r/message.rb, line 51
51:     def type
52:       case super
53:         when 'chat' then :chat
54:         when 'error' then :error
55:         when 'groupchat' then :groupchat
56:         when 'headline' then :headline
57:         when 'normal' then :normal
58:         else nil
59:       end
60:     end

Set the type of the Message stanza (see Message#type for details)

v:[Symbol] or nil

[Source]

    # File lib/xmpp4r/message.rb, line 65
65:     def type=(v)
66:       case v
67:         when :chat then super('chat')
68:         when :error then super('error')
69:         when :groupchat then super('groupchat')
70:         when :headline then super('headline')
71:         when :normal then super('normal')
72:         else super(nil)
73:       end
74:     end

Add a sub-element

Will be converted to [X] if named "x"

element:[REXML::Element] to add

[Source]

    # File lib/xmpp4r/message.rb, line 33
33:     def typed_add(element)
34:       if element.kind_of?(REXML::Element) && (element.name == 'x')
35:         super(X::import(element))
36:       else
37:         super(element)
38:       end
39:     end

Get the first <x/> element in this stanza, or nil if none found.

namespace:[String] Optional, find the first <x/> element having this xmlns
result:[REXML::Element] or nil

[Source]

    # File lib/xmpp4r/message.rb, line 88
88:     def x(namespace=nil)
89:       each_element('x') { |x|
90:         if namespace.nil? or namespace == x.namespace
91:           return x
92:         end
93:       }
94:       nil
95:     end

[Validate]