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 102
102:     def Message.import(xmlstanza)
103:       Message::new.import(xmlstanza)
104:     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 93
93:     def body
94:       first_element_text('body')
95:     end

Sets the message’s body

b:[String] body to set

[Source]

     # File lib/xmpp4r/message.rb, line 110
110:     def body=(b)
111:       replace_element_text('body', b)
112:     end

Sets the message’s body

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

[Source]

     # File lib/xmpp4r/message.rb, line 119
119:     def set_body(b)
120:       self.body = b
121:       self
122:     end

sets the message’s subject

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

[Source]

     # File lib/xmpp4r/message.rb, line 137
137:     def set_subject(s)
138:       self.subject = s
139:       self
140:     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 160
160:     def set_thread(s)
161:       self.thread = s
162:       self
163:     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 144
144:     def subject
145:       first_element_text('subject')
146:     end

sets the message’s subject

s:[String] subject to set

[Source]

     # File lib/xmpp4r/message.rb, line 128
128:     def subject=(s)
129:       replace_element_text('subject', s)
130:     end

Returns the message’s thread, or nil

[Source]

     # File lib/xmpp4r/message.rb, line 167
167:     def thread
168:       first_element_text('thread')
169:     end

sets the message’s thread

s:[String] thread to set

[Source]

     # File lib/xmpp4r/message.rb, line 151
151:     def thread=(s)
152:       delete_elements('thread')
153:       replace_element_text('thread', s) unless s.nil?
154:     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 of this stanza, or nil if none found.

[Source]

    # File lib/xmpp4r/message.rb, line 86
86:     def x
87:       first_element('x')
88:     end

[Validate]