class Jabber::Message

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

Constants

CHAT_STATES

Public Class Methods

new(to = nil, body = nil) click to toggle source

Create a new message

>to

a JID or a String object to send the message to.

>body

the message's body

Calls superclass method
# 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

Public Instance Methods

body() click to toggle source

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
body=(b) click to toggle source

Sets the message's body

b
String

body to set

# File lib/xmpp4r/message.rb, line 89
def body=(b)
  replace_element_text('body', b)
end
chat_state() click to toggle source

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
chat_state=(s) click to toggle source

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
set_body(b) click to toggle source

Sets the message's body

b
String

body to set

return
REXML::Element

self for chaining

# File lib/xmpp4r/message.rb, line 98
def set_body(b)
  self.body = b
  self
end
set_chat_state(s) click to toggle source

Sets the message's chat state

# File lib/xmpp4r/message.rb, line 168
def set_chat_state(s)
  self.state = s
  self
end
set_subject(s) click to toggle source

sets the message's subject

s
String

subject to set

return
REXML::Element

self for chaining

# File lib/xmpp4r/message.rb, line 116
def set_subject(s)
  self.subject = s
  self
end
set_thread(s) click to toggle source

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

# File lib/xmpp4r/message.rb, line 139
def set_thread(s)
  self.thread = s
  self
end
set_type(v) click to toggle source

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

v
Symbol

or nil

# File lib/xmpp4r/message.rb, line 73
def set_type(v)
  self.type = v
  self
end
subject() click to toggle source

Returns the message's subject, or nil

# File lib/xmpp4r/message.rb, line 123
def subject
  first_element_text('subject')
end
subject=(s) click to toggle source

sets the message's subject

s
String

subject to set

# File lib/xmpp4r/message.rb, line 107
def subject=(s)
  replace_element_text('subject', s)
end
thread() click to toggle source

Returns the message's thread, or nil

# File lib/xmpp4r/message.rb, line 146
def thread
  first_element_text('thread')
end
thread=(s) click to toggle source

sets the message's thread

s
String

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
type() click to toggle source

Get the type of the Message stanza

The following Symbols are allowed:

  • :chat

  • :error

  • :groupchat

  • :headline

  • :normal

result
Symbol

or nil

Calls superclass method
# 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
type=(v) click to toggle source

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

v
Symbol

or nil

Calls superclass method
# 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