### Home Classes Methods

### In Files

- lib/xmpp4r/message.rb

### Parent

XMPPStanza

### Methods

- ::new
- #body
- #body=
- #chat_state
- #chat_state=
- #set_body
- #set_chat_state
- #set_subject
- #set_thread
- #set_type
- #set_xhtml_body
- #subject
- #subject=
- #thread
- #thread=
- #type
- #type=
- #xhtml_body
- #xhtml_body=

### Included Modules

- Jabber::XParent

### Files

- CHANGELOG
- COPYING
- LICENSE
- README.rdoc
- README_ruby19.txt

### Class/Module Index

Quicksearch

- Jabber
- Jabber::ArgumentError
- Jabber::Bytestreams
- Jabber::Bytestreams::IBB
- Jabber::Bytestreams::IBBInitiator
- Jabber::Bytestreams::IBBQueueItem
- Jabber::Bytestreams::IBBTarget
- Jabber::Bytestreams::IqQueryBytestreams
- Jabber::Bytestreams::IqSi
- Jabber::Bytestreams::IqSiFile
- Jabber::Bytestreams::IqSiFileRange
- Jabber::Bytestreams::SOCKS5Bytestreams
- Jabber::Bytestreams::SOCKS5BytestreamsInitiator
- Jabber::Bytestreams::SOCKS5BytestreamsPeer
- Jabber::Bytestreams::SOCKS5BytestreamsServer
- Jabber::Bytestreams::SOCKS5BytestreamsServerStreamHost
- Jabber::Bytestreams::SOCKS5BytestreamsTarget
- Jabber::Bytestreams::SOCKS5Socket
- Jabber::Bytestreams::StreamHost
- Jabber::Bytestreams::StreamHostUsed
- Jabber::Callback
- Jabber::CallbackList
- Jabber::Caps
- Jabber::Caps::C
- Jabber::Caps::Helper
- Jabber::Client
- Jabber::ClientAuthenticationFailure
- Jabber::Command
- Jabber::Command::IqCommand
- Jabber::Command::Responder
- Jabber::Component
- Jabber::ComponentAuthenticationFailure
- Jabber::Connection
- Jabber::Connection::SSLSocketUTF8
- Jabber::Dataforms
- Jabber::Dataforms::XData
- Jabber::Dataforms::XDataField
- Jabber::Dataforms::XDataInstructions
- Jabber::Dataforms::XDataReported
- Jabber::Dataforms::XDataTitle
- Jabber::Delay
- Jabber::Delay::XDelay
- Jabber::Discovery
- Jabber::Discovery::Feature
- Jabber::Discovery::Helper
- Jabber::Discovery::Identity
- Jabber::Discovery::IqQueryDiscoInfo
- Jabber::Discovery::IqQueryDiscoItems
- Jabber::Discovery::Item
- Jabber::Discovery::Responder
- Jabber::EntityTime
- Jabber::EntityTime::IqTime
- Jabber::EntityTime::Responder
- Jabber::ErrorResponse
- Jabber::FeatureNegotiation
- Jabber::FeatureNegotiation::IqFeature
- Jabber::FileTransfer
- Jabber::FileTransfer::FileSource
- Jabber::FileTransfer::Helper
- Jabber::FileTransfer::TransferSource
- Jabber::Framework
- Jabber::Framework::Base
- Jabber::Framework::Bot
- Jabber::HTTPBinding
- Jabber::HTTPBinding::Client
- Jabber::IdGenerator
- Jabber::InvalidChatState
- Jabber::Iq
- Jabber::IqQuery
- Jabber::JID
- Jabber::JabberError
- Jabber::LastActivity
- Jabber::LastActivity::Helper
- Jabber::LastActivity::IqQueryLastActivity
- Jabber::MUC
- Jabber::MUC::IqQueryMUCAdmin
- Jabber::MUC::IqQueryMUCAdminItem
- Jabber::MUC::IqQueryMUCOwner
- Jabber::MUC::MUCBrowser
- Jabber::MUC::MUCClient
- Jabber::MUC::SimpleMUCClient
- Jabber::MUC::UserItem
- Jabber::MUC::XMUC
- Jabber::MUC::XMUCUser
- Jabber::MUC::XMUCUserInvite
- Jabber::MUC::XMUCUserItem
- Jabber::Message
- Jabber::NoNameXmlnsRegistered
- Jabber::NotConnected
- Jabber::Observable
- Jabber::Observable::Contact
- Jabber::Observable::PubSub
- Jabber::Observable::PubSub::AlreadySet
- Jabber::Observable::PubSub::NoService
- Jabber::Observable::Subscriptions
- Jabber::Presence
- Jabber::PubSub
- Jabber::PubSub::Configuration
- Jabber::PubSub::Event
- Jabber::PubSub::EventItem
- Jabber::PubSub::EventItems
- Jabber::PubSub::IqPubSub
- Jabber::PubSub::IqPubSubOwner
- Jabber::PubSub::Item
- Jabber::PubSub::Items
- Jabber::PubSub::NodeBrowser
- Jabber::PubSub::NodeConfig
- Jabber::PubSub::NodeHelper
- Jabber::PubSub::OAuthPubSubStreamHelper
- Jabber::PubSub::OAuthServiceHelper
- Jabber::PubSub::OwnerNodeConfig
- Jabber::PubSub::Publish
- Jabber::PubSub::Retract
- Jabber::PubSub::ServiceHelper
- Jabber::PubSub::Subscription
- Jabber::PubSub::SubscriptionConfig
- Jabber::PubSub::Unsubscribe
- Jabber::RPC
- Jabber::RPC::Client
- Jabber::RPC::IqQueryRPC
- Jabber::RPC::Server
- Jabber::Reliable
- Jabber::Reliable::Connection
- Jabber::Reliable::Listener
- Jabber::Roster
- Jabber::Roster::Helper
- Jabber::Roster::Helper::RosterItem
- Jabber::Roster::IqQueryRoster
- Jabber::Roster::RosterItem
- Jabber::Roster::RosterX
- Jabber::Roster::RosterXItem
- Jabber::Roster::XRoster
- Jabber::Roster::XRosterItem
- Jabber::SASL
- Jabber::SASL::Anonymous
- Jabber::SASL::Base
- Jabber::SASL::DigestMD5
- Jabber::SASL::Plain
- Jabber::SOCKS5Error
- Jabber::Semaphore
- Jabber::ServerDisconnected
- Jabber::Stream
- Jabber::Stream::ThreadBlock
- Jabber::StreamParser
- Jabber::Test
- Jabber::Test::ListenerMocker
- Jabber::UserLocation
- Jabber::UserLocation::Helper
- Jabber::UserLocation::Location
- Jabber::UserTune
- Jabber::UserTune::Helper
- Jabber::UserTune::Tune
- Jabber::Vcard
- Jabber::Vcard::Helper
- Jabber::Vcard::IqVcard
- Jabber::Version
- Jabber::Version::IqQueryVersion
- Jabber::Version::Responder
- Jabber::Version::SimpleResponder
- Jabber::X
- Jabber::XHTML
- Jabber::XHTML::Body
- Jabber::XHTML::HTML
- Jabber::XMPPElement
- Jabber::XMPPStanza
- Jabber::XParent
- REXML
- REXML::Element
- REXML::IOSource
- XMLRPC
- XMLRPC::Create
- Base64
- ObservableThing
- QObserver
- ThreadStore

No matching classes.

# 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

    # 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 198
    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 205
    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 214
    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 162
    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 185
    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

set_xhtml_body(b) click to toggle source

Sets the message's xhtml body

b

String

  xhtml body to set (Note: must be a valid xhtml)

return

REXML::Element

  self for chaining

    # File lib/xmpp4r/message.rb, line 144
    def set_xhtml_body(b)
      self.xhtml_body = b
      self
    end

subject() click to toggle source

Returns the message's subject, or nil

    # File lib/xmpp4r/message.rb, line 169
    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 153
    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 192
    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 176
    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

    # 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 Message#type for details)

v

Symbol

  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

xhtml_body() click to toggle source

Returns the message's xhtml body, or nil. This is the message's xhtml-text content.

    # File lib/xmpp4r/message.rb, line 106
    def xhtml_body
      html = first_element('html', 'http://jabber.org/protocol/xhtml-im')

      if html
        html.first_element_content('body', 'http://www.w3.org/1999/xhtml')
      else
        first_element_content('body', 'http://www.w3.org/1999/xhtml')
      end
    end

xhtml_body=(b) click to toggle source

Sets the message's xhtml body

b

String

  xhtml body to set (Note: must be a valid xhtml)

    # File lib/xmpp4r/message.rb, line 120
    def xhtml_body=(b)
      begin
        b = REXML::Document.new("<root>#{b}</root>")
      rescue REXML::ParseException
        raise ArgumentError, "Body is not a valid xhtml. Have you forgot to close some tag?"
      end

      html = first_element('html', 'http://jabber.org/protocol/xhtml-im')

      if html
        html.replace_element_content('body', b, 'http://www.w3.org/1999/xhtml')
      else
        el = REXML::Element.new('html')
        el.add_namespace('http://jabber.org/protocol/xhtml-im')
        el.replace_element_content('body', b, 'http://www.w3.org/1999/xhtml')
        add_element(el)
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.