Class Jabber::Roster::Helper::RosterItem
In: lib/xmpp4r/roster/helper/roster.rb
Parent: Jabber::Roster::RosterItem
Message Presence XMPPStanza Iq Singleton IdGenerator XMPPElement X IqQuery Error Connection Client Component Client Comparable JID RuntimeError AuthenticationFailure ErrorException NoNameXmlnsRegistered SOCKS5Error REXML::Element Stream SOCKS5Bytestreams SOCKS5BytestreamsTarget SOCKS5BytestreamsInitiator XMPPElement StreamHost IqSiFileRange IqSiFile StreamHostUsed IqSi XRosterItem RosterItem IqFeature XMUCUserItem XMUCUserInvite IqPubSub Items Subscription IqPubSubOwner Item Event Feature Item Identity XDataField XDataReported XDataTitle XDataInstructions IqVcard SOCKS5BytestreamsServerStreamHost TCPSocket SOCKS5Socket IqQuery IqQueryBytestreams IqQueryVersion IqQueryRoster IqQueryMUCOwner IqQueryRPC IqQueryDiscoItems IqQueryDiscoInfo IBB IBBTarget IBBInitiator Responder SimpleResponder Iq IqCommand RosterXItem XRoster RosterX X XMUCUser XMUC XDelay XData XParent MUCClient SimpleMUCClient XMLRPC::ParserWriterChooseMixin Client Server XMLRPC::ParseContentType XMLRPC::BasicServer Base DigestMD5 Plain ServiceHelper NodeHelper FileSource CallbackList Callback Semaphore StreamParser SOCKS5BytestreamsPeer SOCKS5BytestreamsServer IBBQueueItem Responder Helper MUCBrowser NodeBrowser Helper Helper lib/xmpp4r/authenticationfailure.rb lib/xmpp4r/xmppstanza.rb lib/xmpp4r/callbacks.rb lib/xmpp4r/idgenerator.rb lib/xmpp4r/connection.rb lib/xmpp4r/iq.rb lib/xmpp4r/jid.rb lib/xmpp4r/errorexception.rb lib/xmpp4r/client.rb lib/xmpp4r/stream.rb lib/xmpp4r/semaphore.rb lib/xmpp4r/streamparser.rb lib/xmpp4r/x.rb lib/xmpp4r/error.rb lib/xmpp4r/component.rb lib/xmpp4r/query.rb lib/xmpp4r/xmppelement.rb lib/xmpp4r/message.rb lib/xmpp4r/presence.rb lib/xmpp4r/bytestreams/helper/ibb/initiator.rb lib/xmpp4r/bytestreams/iq/si.rb lib/xmpp4r/bytestreams/iq/bytestreams.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb lib/xmpp4r/bytestreams/helper/ibb/base.rb lib/xmpp4r/bytestreams/helper/ibb/target.rb Bytestreams XParent lib/xmpp4r/version/iq/version.rb lib/xmpp4r/version/helper/responder.rb lib/xmpp4r/version/helper/simpleresponder.rb Version lib/xmpp4r/command/iq/command.rb lib/xmpp4r/command/helper/responder.rb Command lib/xmpp4r/roster/helper/roster.rb lib/xmpp4r/roster/iq/roster.rb lib/xmpp4r/roster/x/roster.rb Roster lib/xmpp4r/feature_negotiation/iq/feature.rb FeatureNegotiation lib/xmpp4r/muc/x/muc.rb lib/xmpp4r/muc/helper/mucclient.rb lib/xmpp4r/muc/x/mucuseritem.rb lib/xmpp4r/muc/helper/mucbrowser.rb lib/xmpp4r/muc/x/mucuserinvite.rb lib/xmpp4r/muc/iq/mucowner.rb lib/xmpp4r/muc/helper/simplemucclient.rb MUC lib/xmpp4r/rpc/helper/server.rb lib/xmpp4r/rpc/helper/client.rb lib/xmpp4r/rpc/iq/rpc.rb RPC lib/xmpp4r/sasl.rb SASL lib/xmpp4r/delay/x/delay.rb Delay lib/xmpp4r/pubsub/stanzas/subscription.rb lib/xmpp4r/pubsub/helper/servicehelper.rb lib/xmpp4r/pubsub/stanzas/item.rb lib/xmpp4r/pubsub/helper/nodehelper.rb lib/xmpp4r/pubsub/iq/pubsub.rb lib/xmpp4r/pubsub/stanzas/event.rb lib/xmpp4r/pubsub/helper/nodebrowser.rb lib/xmpp4r/pubsub/stanzas/items.rb PubSub lib/xmpp4r/httpbinding/client.rb HTTPBinding lib/xmpp4r/bytestreams/helper/filetransfer.rb TransferSource FileTransfer lib/xmpp4r/discovery/iq/discoinfo.rb lib/xmpp4r/discovery/iq/discoitems.rb Discovery lib/xmpp4r/dataforms/x/data.rb Dataforms lib/xmpp4r/vcard/helper/vcard.rb lib/xmpp4r/vcard/iq/vcard.rb Vcard Jabber dot/m_80_0.png

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

Methods

Attributes

presences  [R]  Tracked (online) presences of this RosterItem

Public Class methods

Initialize an empty RosterItem

[Source]

     # File lib/xmpp4r/roster/helper/roster.rb, line 364
364:         def initialize(stream)
365:           super()
366:           @stream = stream
367:           @presences = []
368:           @presences_lock = Mutex.new
369:         end

Public Instance methods

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. Presence stanzas with type == :unavailable or type == :error will be deleted as this indicates that this resource has gone offline.

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

[Source]

     # File lib/xmpp4r/roster/helper/roster.rb, line 441
441:         def add_presence(newpres)
442:           @presences_lock.synchronize {
443:             # Delete old presences with the same JID
444:             @presences.delete_if do |pres|
445:               pres.from == newpres.from or pres.from.resource.nil?
446:             end
447: 
448:             if newpres.type == :error and newpres.from.resource.nil?
449:               # Replace by single error presence
450:               @presences = [newpres]
451:             else
452:               # Add new presence
453:               @presences.push(newpres)
454:             end
455: 
456:             @presences.sort!
457:           }
458:         end

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’.

[Source]

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

Iterate through all received <presence/> stanzas

[Source]

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

Is any presence of this person on-line?

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

[Source]

     # File lib/xmpp4r/roster/helper/roster.rb, line 400
400:         def online?
401:           @presences_lock.synchronize {
402:             @presences.select { |pres|
403:               pres.type.nil?
404:             }.size > 0
405:           }
406:         end

Get specific presence

jid:[JID] Full JID

[Source]

     # File lib/xmpp4r/roster/helper/roster.rb, line 420
420:         def presence(jid)
421:           @presences_lock.synchronize {
422:             @presences.each { |pres|
423:               return(pres) if pres.from == jid
424:             }
425:           }
426:           nil
427:         end

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 ErrorException upon failure.

[Source]

     # File lib/xmpp4r/roster/helper/roster.rb, line 388
388:         def remove
389:           request = Iq.new_rosterset
390:           request.query.add(Jabber::Roster::RosterItem.new(jid, nil, :remove))
391:           @stream.send_with_id(request) { true }
392:           # Removing from list is handled by Roster#handle_iq_query_roster
393:         end

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

[Source]

     # File lib/xmpp4r/roster/helper/roster.rb, line 374
374:         def send
375:           request = Iq.new_rosterset
376:           request.query.add(self)
377:           @stream.send(request)
378:         end

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. ;-)

[Source]

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

Unsubscribe from a contact‘s presence

This method waits for a presence with type=‘unsubscribed’ from the contact. It may throw ErrorException 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.

[Source]

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

[Validate]