### Home Classes Methods

### In Files

- lib/xmpp4r/roster/helper/roster.rb

### Parent

Jabber::Roster::RosterItem

### Methods

- ::new
- #add_presence
- #cancel_subscription
- #each_presence
- #online?
- #presence
- #presence_of
- #remove
- #send
- #subscribe
- #unsubscribe

### 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::Roster::Helper::RosterItem

These are extensions to RosterItem to carry presence information. This information is not stored in XML!

### Attributes

presences[R]

Tracked (online) presences of this RosterItem

### Public Class Methods

new(stream) click to toggle source

Initialize an empty RosterItem

    # File lib/xmpp4r/roster/helper/roster.rb, line 379
    def initialize(stream)
      super()
      @stream = stream
      @presences = []
      @presences_lock = Mutex.new
    end

### Public Instance Methods

add_presence(newpres) click to toggle source

Add presence and sort presences (unless type is :unavailable or :error)

This overwrites previous stanzas with the same destination JID to keep track of resources. Old presence stanzas with `type == :unavailable` will be deleted.

If `type == :error` and the presence's origin has no specific resource the contact is treated completely offline.

    # File lib/xmpp4r/roster/helper/roster.rb, line 466
    def add_presence(newpres)
      @presences_lock.synchronize {
        # Delete old presences with the same JID
        @presences.delete_if do |pres|
          pres.from == newpres.from or pres.from.resource.nil? or pres.type == :unavailable
        end

        if newpres.type == :error and newpres.from.resource.nil?
          # Replace by single error presence
          @presences = [newpres]
        else
          # Add new presence
          @presences.push(newpres)
        end

        @presences.sort!
      }
    end

cancel_subscription() click to toggle source

Deny the contact to see your presence.

This method will not wait and returns immediately as you will need no confirmation for this action.

Though, you will get a roster update for that item, carrying either subscription='to' or 'none'.

    # File lib/xmpp4r/roster/helper/roster.rb, line 525
    def cancel_subscription
      pres = Presence.new.set_type(:unsubscribed).set_to(jid)
      @stream.send(pres)
    end

each_presence(&block) click to toggle source

Iterate through all received `<presence/>` stanzas

    # File lib/xmpp4r/roster/helper/roster.rb, line 425
    def each_presence(&block)
      # Don't lock here, we don't know what block does...
      @presences.each { |pres|
        yield(pres)
      }
    end

online?() click to toggle source

Is any presence of this person on-line?

(Or is there any presence? Unavailable presences are deleted.)

    # File lib/xmpp4r/roster/helper/roster.rb, line 415
    def online?
      @presences_lock.synchronize {
        @presences.select { |pres|
          pres.type.nil?
        }.size > 0
      }
    end

presence() click to toggle source

Get presence of highest-priority available resource of this person

Returns `nil` if contact is offline

    # File lib/xmpp4r/roster/helper/roster.rb, line 448
    def presence
      @presences_lock.synchronize {
        @presences.select { |pres|
          pres.type.nil?
        }.max { |pres1, pres2| (pres1.priority || 0) <=> (pres2.priority || 0) }
      }
    end

presence_of(jid) click to toggle source

Get specific presence

jid

JID

  Full JID with resource

    # File lib/xmpp4r/roster/helper/roster.rb, line 435
    def presence_of(jid)
      @presences_lock.synchronize {
        @presences.each { |pres|
          return(pres) if pres.from == jid
        }
      }
      nil
    end

remove() click to toggle source

Remove item

This cancels both subscription from the contact to you and from you to the contact.

The methods waits for a roster push from the server (success) or throws ServerError upon failure.

    # File lib/xmpp4r/roster/helper/roster.rb, line 403
    def remove
      request = Iq.new_rosterset
      request.query.add(Jabber::Roster::RosterItem.new(jid, nil, :remove))
      @stream.send_with_id(request)
      # Removing from list is handled by Roster#handle_iq_query_roster
    end

send() click to toggle source

Send the updated RosterItem to the server, i.e. if you modified iname, groups, ...

    # File lib/xmpp4r/roster/helper/roster.rb, line 389
    def send
      request = Iq.new_rosterset
      request.query.add(self)
      @stream.send(request)
    end

subscribe() click to toggle source

Send subscription request to the user

The block given to Jabber::Roster::Roster#add_update_callback will be called, carrying the RosterItem with ask="subscribe"

This function returns immediately after sending the subscription request and will not wait of approval or declination as it may take months for the contact to decide. ;-)

    # File lib/xmpp4r/roster/helper/roster.rb, line 494
    def subscribe
      pres = Presence.new.set_type(:subscribe).set_to(jid.strip)
      @stream.send(pres)
    end

unsubscribe() click to toggle source

Unsubscribe from a contact's presence

This method waits for a presence with type='unsubscribed' from the contact. It may throw ServerError upon failure.

subscription attribute of the item is from or none afterwards. As long as you don't remove that item and subscription='from' the contact is subscribed to your presence.

    # File lib/xmpp4r/roster/helper/roster.rb, line 509
    def unsubscribe
      pres = Presence.new.set_type(:unsubscribe).set_to(jid.strip)
      @stream.send(pres) { |answer|
        answer.type == :unsubscribed and
        answer.from.strip == pres.to
      }
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.