| Class | Jabber::Message |
| In: |
lib/xmpp4r/message.rb
|
| Parent: | XMPPStanza |
The Message class manages the <message/> stanzas, which is used for all messaging communication.
| CHAT_STATES | = | %w(active composing gone inactive paused).freeze |
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 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
Returns the current chat state, or nil if no chat state is set
# 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
# 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 |
# 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
# 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 |
# File lib/xmpp4r/message.rb, line 116
116: def set_subject(s)
117: self.subject = s
118: self
119: end
Get the type of the Message stanza
The following Symbols are allowed:
| result: | [Symbol] or nil |
# 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 |
# 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