| Class | Jabber::Message |
| In: |
lib/xmpp4r/message.rb
|
| Parent: | XMLStanza |
The Message class manages the <message/> stanzas, which is used for all messaging communication.
Create a new message from a stanza, by copying all attributes and children from it.
| xmlstanza: | [REXML::Element] Source |
| return: | [Message] Result |
# 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 |
# 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
Sets the message‘s body
| b: | [String] body to set |
| return: | [REXML::Element] self for chaining |
# 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 |
# File lib/xmpp4r/message.rb, line 137
137: def set_subject(s)
138: self.subject = s
139: self
140: end
Get the type of the Message stanza
The following Symbols are allowed:
| result: | [Symbol] or nil |
# 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 |
# 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 |
# 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