The Message class manages the <message/> stanzas, which is used for all messaging communication.
Create a new message
a JID or a String object to send the message to.
the message's body
# File lib/xmpp4r/message.rb, line 25 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
Returns the message's body, or nil. This is the message's plain-text content.
# File lib/xmpp4r/message.rb, line 81 def body first_element_text('body') end
Sets the message's body
body to set
# File lib/xmpp4r/message.rb, line 89 def body=(b) replace_element_text('body', b) end
Returns the current chat state, or nil if no chat state is set
# File lib/xmpp4r/message.rb, line 152 def chat_state each_elements(*CHAT_STATES) { |el| return el.name.to_sym } return nil end
Sets the chat state :active, :composing, :gone, :inactive, :paused
# File lib/xmpp4r/message.rb, line 159 def chat_state=(s) s = s.to_s raise InvalidChatState, "Chat state must be one of #{CHAT_STATES.join(', ')}" unless CHAT_STATES.include?(s) CHAT_STATES.each { |state| delete_elements(state) } add_element(REXML::Element.new(s).add_namespace('http://jabber.org/protocol/chatstates')) end
Sets the message's body
body to set
self for chaining
# File lib/xmpp4r/message.rb, line 98 def set_body(b) self.body = b self end
Sets the message's chat state
# File lib/xmpp4r/message.rb, line 168 def set_chat_state(s) self.state = s self end
sets the message's subject
subject to set
self for chaining
# File lib/xmpp4r/message.rb, line 116 def set_subject(s) self.subject = s self end
gets the message's thread (chaining-friendly) Please note that this are not [Thread] but a [String]-Identifier to track conversations
thread to set
# File lib/xmpp4r/message.rb, line 139 def set_thread(s) self.thread = s self end
Set the type of the Message stanza (chaining-friendly)
or nil
# File lib/xmpp4r/message.rb, line 73 def set_type(v) self.type = v self end
Returns the message's subject, or nil
# File lib/xmpp4r/message.rb, line 123 def subject first_element_text('subject') end
sets the message's subject
subject to set
# File lib/xmpp4r/message.rb, line 107 def subject=(s) replace_element_text('subject', s) end
Returns the message's thread, or nil
# File lib/xmpp4r/message.rb, line 146 def thread first_element_text('thread') end
sets the message's thread
thread to set
# File lib/xmpp4r/message.rb, line 130 def thread=(s) delete_elements('thread') replace_element_text('thread', s) unless s.nil? end
Get the type of the Message stanza
The following Symbols are allowed:
:chat
:error
:groupchat
:headline
:normal
or nil
# File lib/xmpp4r/message.rb, line 45 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
Set the type of the Message stanza (see #type for details)
or nil
# File lib/xmpp4r/message.rb, line 59 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