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

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

Methods

body   body=   chat_state   chat_state=   new   set_body   set_chat_state   set_subject   set_thread   set_type   subject   subject=   thread   thread=   type   type=  

Included Modules

XParent

Constants

CHAT_STATES = %w(active composing gone inactive paused).freeze

Public Class methods

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 25
25:     def initialize(to = nil, body = nil)
26:       super()
27:       if not to.nil?
28:         set_to(to)
29:       end
30:       if !body.nil?
31:         add_element(REXML::Element.new("body").add_text(body))
32:       end
33:     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 81
81:     def body
82:       first_element_text('body')
83:     end

Sets the message‘s body

b:[String] body to set

[Source]

    # File lib/xmpp4r/message.rb, line 89
89:     def body=(b)
90:       replace_element_text('body', b)
91:     end

Returns the current chat state, or nil if no chat state is set

[Source]

     # File lib/xmpp4r/message.rb, line 152
152:     def chat_state
153:       each_elements(*CHAT_STATES) { |el| return el.name.to_sym }
154:       return nil
155:     end

Sets the chat state :active, :composing, :gone, :inactive, :paused

[Source]

     # File lib/xmpp4r/message.rb, line 159
159:     def chat_state=(s)
160:       s = s.to_s
161:       raise InvalidChatState, "Chat state must be one of #{CHAT_STATES.join(', ')}" unless CHAT_STATES.include?(s)
162:       CHAT_STATES.each { |state| delete_elements(state) }
163:       add_element(REXML::Element.new(s).add_namespace('http://jabber.org/protocol/chatstates'))
164:     end

Sets the message‘s body

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

[Source]

     # File lib/xmpp4r/message.rb, line 98
 98:     def set_body(b)
 99:       self.body = b
100:       self
101:     end

Sets the message‘s chat state

[Source]

     # File lib/xmpp4r/message.rb, line 168
168:     def set_chat_state(s)
169:       self.state = s
170:       self
171:     end

sets the message‘s subject

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

[Source]

     # File lib/xmpp4r/message.rb, line 116
116:     def set_subject(s)
117:       self.subject = s
118:       self
119:     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 139
139:     def set_thread(s)
140:       self.thread = s
141:       self
142:     end

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

v:[Symbol] or nil

[Source]

    # File lib/xmpp4r/message.rb, line 73
73:     def set_type(v)
74:       self.type = v
75:       self
76:     end

Returns the message‘s subject, or nil

[Source]

     # File lib/xmpp4r/message.rb, line 123
123:     def subject
124:       first_element_text('subject')
125:     end

sets the message‘s subject

s:[String] subject to set

[Source]

     # File lib/xmpp4r/message.rb, line 107
107:     def subject=(s)
108:       replace_element_text('subject', s)
109:     end

Returns the message‘s thread, or nil

[Source]

     # File lib/xmpp4r/message.rb, line 146
146:     def thread
147:       first_element_text('thread')
148:     end

sets the message‘s thread

s:[String] thread to set

[Source]

     # File lib/xmpp4r/message.rb, line 130
130:     def thread=(s)
131:       delete_elements('thread')
132:       replace_element_text('thread', s) unless s.nil?
133:     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 45
45:     def type
46:       case super
47:         when 'chat' then :chat
48:         when 'error' then :error
49:         when 'groupchat' then :groupchat
50:         when 'headline' then :headline
51:         when 'normal' then :normal
52:         else nil
53:       end
54:     end

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

v:[Symbol] or nil

[Source]

    # File lib/xmpp4r/message.rb, line 59
59:     def type=(v)
60:       case v
61:         when :chat then super('chat')
62:         when :error then super('error')
63:         when :groupchat then super('groupchat')
64:         when :headline then super('headline')
65:         when :normal then super('normal')
66:         else super(nil)
67:       end
68:     end

[Validate]