### Home Classes Methods

### In Files

- lib/xmpp4r/presence.rb

### Parent

Jabber::XMPPStanza

### Methods

- ::new
- #<=>
- #cmp_interest
- #priority
- #priority=
- #set_priority
- #set_show
- #set_status
- #set_type
- #show
- #show=
- #status
- #status=
- #type
- #type=

### Included Modules

- Comparable
- 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::Presence

The presence class is used to construct presence messages to send to the Jabber service.

### Constants

PRESENCE_STATUS

  Compare two presences. The most suitable to talk with is the biggest.

### Public Class Methods

new(show=nil, status=nil, priority=nil) click to toggle source

Create presence stanza

show

Symbol

  Initial Availability Status (see show)

status

String

  Initial status message

priority

Fixnum

  Initial priority value

    # File lib/xmpp4r/presence.rb, line 24
    def initialize(show=nil, status=nil, priority=nil)
      super()
      set_show(show) if show
      set_status(status) if status
      set_priority(priority) if priority
    end

### Public Instance Methods

<=>(o) click to toggle source

Compare two presences using priority (with cmp_interest as fall-back).

    # File lib/xmpp4r/presence.rb, line 197
    def <=>(o)
      if priority.to_i == o.priority.to_i
        cmp_interest(o)
      else
        priority.to_i <=> o.priority.to_i
      end
    end

cmp_interest(o) click to toggle source

    # File lib/xmpp4r/presence.rb, line 215
    def cmp_interest(o)
      if type.nil?
        if o.type.nil?
          # both available.
          PRESENCE_STATUS[show] <=> PRESENCE_STATUS[o.show]
        else
          return -1
        end
      elsif o.type.nil?
        return 1
      else
        # both are non-nil. We consider this is equal.
        return 0
      end
    end

priority() click to toggle source

Get presence priority, or nil if absent

result

Integer

    # File lib/xmpp4r/presence.rb, line 163
    def priority
       e = first_element_text('priority')
      if e
        return e.to_i
      else
        return nil
      end
    end

priority=(val) click to toggle source

Set presence priority

val

Integer

  Priority value between -128 and +127

Warning: negative values make you receive no subscription requests etc. (RFC3921 - 2.2.2.3.)

    # File lib/xmpp4r/presence.rb, line 178
    def priority=(val)
      if val.nil?
        delete_element('priority')
      else
        replace_element_text('priority', val)
      end
    end

set_priority(val) click to toggle source

Set presence priority (chaining-friendly)

val

Integer

  Priority value between -128 and +127

    # File lib/xmpp4r/presence.rb, line 189
    def set_priority(val)
      self.priority = val
      self
    end

set_show(val) click to toggle source

Set Availability Status (chaining-friendly)

val

Symbol

  or [Nil] See show for explanation

    # File lib/xmpp4r/presence.rb, line 129
    def set_show(val)
      self.show = val
      self
    end

set_status(val) click to toggle source

Set status message (chaining-friendly)

val

String

  or nil

    # File lib/xmpp4r/presence.rb, line 155
    def set_status(val)
      self.status = val
      self
    end

set_type(val) click to toggle source

Set type of presence (chaining-friendly)

val

Symbol

  See type for possible subscription types

    # File lib/xmpp4r/presence.rb, line 76
    def set_type(val)
      self.type = val
      self
    end

show() click to toggle source

Get Availability Status (RFC3921 - 5.2)

result

Symbol

  or [Nil] Valid values according to RFC3921:

- nil (Available, no <show/> element)

- :away

- :chat (Free for chat)

- :dnd (Do not disturb)

- :xa (Extended away)

    # File lib/xmpp4r/presence.rb, line 89
    def show
      e = first_element('show')
      text = e ? e.text : nil
      case text
        when 'away' then :away
        when 'chat' then :chat
        when 'dnd' then :dnd
        when 'xa' then :xa
        else nil
      end
    end

show=(val) click to toggle source

Set Availability Status

val

Symbol

  or [Nil] See show for explanation

    # File lib/xmpp4r/presence.rb, line 104
    def show=(val)
      xe = first_element('show')
      if xe.nil?
        xe = add_element('show')
      end
      case val
        when String then raise "Invalid value for show."
        when :away then text = 'away'
        when :chat then text = 'chat'
        when :dnd then text = 'dnd'
        when :xa then text = 'xa'
        when nil then text = nil
        else raise "Invalid value for show."
      end

      if text.nil?
        delete_element(xe)
      else
        xe.text = text
      end
    end

status() click to toggle source

Get status message

result

String

  or nil

    # File lib/xmpp4r/presence.rb, line 137
    def status
      first_element_text('status')
    end

status=(val) click to toggle source

Set status message

val

String

  or nil

    # File lib/xmpp4r/presence.rb, line 144
    def status=(val)
      if val.nil?
        delete_element('status')
      else
        replace_element_text('status', val)
      end
    end

type() click to toggle source

Get type of presence

result

Symbol

  or [Nil] Possible values are:

- :error

- :probe (Servers send this to request presence information)

- :subscribe (Subscription request)

- :subscribed (Subscription approval)

- :unavailable (User has gone offline)

- :unsubscribe (Unsubscription request)

- :unsubscribed (Unsubscription approval)

- nil

    (available)

See RFC3921 - 2.2.1. for explanation.

    # File lib/xmpp4r/presence.rb, line 44
    def type
      case super
        when 'error' then :error
        when 'probe' then :probe
        when 'subscribe' then :subscribe
        when 'subscribed' then :subscribed
        when 'unavailable' then :unavailable
        when 'unsubscribe' then :unsubscribe
        when 'unsubscribed' then :unsubscribed
        else nil
      end
    end

type=(val) click to toggle source

Set type of presence

val

Symbol

  See type for possible subscription types

    # File lib/xmpp4r/presence.rb, line 60
    def type=(val)
      case val
        when :error then super('error')
        when :probe then super('probe')
        when :subscribe then super('subscribe')
        when :subscribed then super('subscribed')
        when :unavailable then super('unavailable')
        when :unsubscribe then super('unsubscribe')
        when :unsubscribed then super('unsubscribed')
        else super(nil)
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.