Class: Jabber::Message
- Inherits:
-
XMPPStanza
- Object
- REXML::Element
- XMPPElement
- XMPPStanza
- Jabber::Message
- Includes:
- XParent
- Defined in:
- lib/vendor/xmpp4r/lib/xmpp4r/message.rb
Overview
The Message class manages the <message/> stanzas, which is used for all messaging communication.
Instance Method Summary collapse
-
#body ⇒ Object
Returns the message’s body, or nil.
-
#body=(b) ⇒ Object
Sets the message’s body.
-
#initialize(to = nil, body = nil) ⇒ Message
constructor
- Create a new message >to
-
a JID or a String object to send the message to.
-
#set_body(b) ⇒ Object
Sets the message’s body.
-
#set_subject(s) ⇒ Object
sets the message’s subject.
-
#set_thread(s) ⇒ Object
- 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.
-
#set_type(v) ⇒ Object
- Set the type of the Message stanza (chaining-friendly) v
- Symbol
-
or nil.
-
#subject ⇒ Object
Returns the message’s subject, or nil.
-
#subject=(s) ⇒ Object
sets the message’s subject.
-
#thread ⇒ Object
Returns the message’s thread, or nil.
-
#thread=(s) ⇒ Object
- sets the message’s thread s
- String
-
thread to set.
-
#type ⇒ Object
Get the type of the Message stanza.
-
#type=(v) ⇒ Object
- Set the type of the Message stanza (see Message#type for details) v
- Symbol
-
or nil.
Methods included from XParent
Methods inherited from XMPPStanza
answer, #answer, #error, #from, #from=, #id, #id=, #normalize, #set_from, #set_id, #set_to, #to, #to=
Methods inherited from XMPPElement
class_for_name_xmlns, #clone, force_xmlns, force_xmlns?, import, name_xmlns, name_xmlns_for_class, #parent=, #set_xml_lang, #typed_add, #xml_lang, #xml_lang=
Methods inherited from REXML::Element
#==, #delete_elements, #first_element, #first_element_text, #import, import, #replace_element_text, #typed_add
Constructor Details
#initialize(to = nil, body = nil) ⇒ Message
Create a new message
- >to
-
a JID or a String object to send the message to.
- >body
-
the message’s body
23 24 25 26 27 28 29 30 31 |
# File 'lib/vendor/xmpp4r/lib/xmpp4r/message.rb', line 23 def initialize(to = nil, body = nil) super() if not to.nil? set_to(to) end if !body.nil? add_element(REXML::Element.new("body").add_text(body)) end end |
Instance Method Details
#body ⇒ Object
Returns the message’s body, or nil. This is the message’s plain-text content.
79 80 81 |
# File 'lib/vendor/xmpp4r/lib/xmpp4r/message.rb', line 79 def body first_element_text('body') end |
#body=(b) ⇒ Object
Sets the message’s body
- b
- String
-
body to set
87 88 89 |
# File 'lib/vendor/xmpp4r/lib/xmpp4r/message.rb', line 87 def body=(b) replace_element_text('body', b) end |
#set_body(b) ⇒ Object
Sets the message’s body
- b
- String
-
body to set
- return
- REXML::Element
-
self for chaining
96 97 98 99 |
# File 'lib/vendor/xmpp4r/lib/xmpp4r/message.rb', line 96 def set_body(b) self.body = b self end |
#set_subject(s) ⇒ Object
sets the message’s subject
- s
- String
-
subject to set
- return
- REXML::Element
-
self for chaining
114 115 116 117 |
# File 'lib/vendor/xmpp4r/lib/xmpp4r/message.rb', line 114 def set_subject(s) self.subject = s self end |
#set_thread(s) ⇒ Object
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
137 138 139 140 |
# File 'lib/vendor/xmpp4r/lib/xmpp4r/message.rb', line 137 def set_thread(s) self.thread = s self end |
#set_type(v) ⇒ Object
Set the type of the Message stanza (chaining-friendly)
- v
- Symbol
-
or nil
71 72 73 74 |
# File 'lib/vendor/xmpp4r/lib/xmpp4r/message.rb', line 71 def set_type(v) self.type = v self end |
#subject ⇒ Object
Returns the message’s subject, or nil
121 122 123 |
# File 'lib/vendor/xmpp4r/lib/xmpp4r/message.rb', line 121 def subject first_element_text('subject') end |
#subject=(s) ⇒ Object
sets the message’s subject
- s
- String
-
subject to set
105 106 107 |
# File 'lib/vendor/xmpp4r/lib/xmpp4r/message.rb', line 105 def subject=(s) replace_element_text('subject', s) end |
#thread ⇒ Object
Returns the message’s thread, or nil
144 145 146 |
# File 'lib/vendor/xmpp4r/lib/xmpp4r/message.rb', line 144 def thread first_element_text('thread') end |
#thread=(s) ⇒ Object
sets the message’s thread
- s
- String
-
thread to set
128 129 130 131 |
# File 'lib/vendor/xmpp4r/lib/xmpp4r/message.rb', line 128 def thread=(s) delete_elements('thread') replace_element_text('thread', s) unless s.nil? end |
#type ⇒ Object
Get the type of the Message stanza
The following Symbols are allowed:
-
:chat
-
:error
-
:groupchat
-
:headline
-
:normal
- result
- Symbol
-
or nil
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/vendor/xmpp4r/lib/xmpp4r/message.rb', line 43 def type case super when 'chat' then :chat when 'error' then :error when 'groupchat' then :groupchat when 'headline' then :headline when 'normal' then :normal else nil end end |
#type=(v) ⇒ Object
Set the type of the Message stanza (see Message#type for details)
- v
- Symbol
-
or nil
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/vendor/xmpp4r/lib/xmpp4r/message.rb', line 57 def type=(v) case v when :chat then super('chat') when :error then super('error') when :groupchat then super('groupchat') when :headline then super('headline') when :normal then super('normal') else super(nil) end end |