| Class | Jabber::Helpers::RosterItem |
| In: |
lib/xmpp4r/helpers/roster.rb
|
| Parent: | Jabber::RosterItem |
These are extensions to RosterItem to carry presence information. This information is not stored in XML!
| presences | [R] | Tracked (online) presences of this RosterItem |
Initialize an empty RosterItem
# File lib/xmpp4r/helpers/roster.rb, line 276
276: def initialize(stream)
277: super()
278: @stream = stream
279: @presences = []
280: end
Add presence (unless type is :unavailable)
This overwrites previous stanzas with the same destination JID to keep track of resources. Presence stanzas with type == :unavailable will be deleted as this indicates that this resource has gone offline.
# File lib/xmpp4r/helpers/roster.rb, line 342
342: def add_presence(newpres)
343: # Delete old presences with the same JID
344: @presences.delete_if do |pres|
345: pres.from == newpres.from
346: end
347: # Add new presence
348: unless newpres.type == :unavailable
349: @presences.push(newpres)
350: end
351: end
Iterate through all received <presence/> stanzas
# File lib/xmpp4r/helpers/roster.rb, line 316
316: def each_presence(&block)
317: @presences.each { |pres|
318: yield(pres)
319: }
320: end
Import another element, also import presences if xe is a RosterItem
| return: | [RosterItem] self |
# File lib/xmpp4r/helpers/roster.rb, line 286
286: def import(xe)
287: super
288: if xe.kind_of?(RosterItem)
289: xe.each_presence { |pres|
290: add_presence(Presence.new.import(pres))
291: }
292: end
293: self
294: end
Is any presence of this person on-line?
(Or is there any presence? Unavailable presences are deleted.)
# File lib/xmpp4r/helpers/roster.rb, line 310
310: def online?
311: @presences.size > 0
312: end
Send the updated RosterItem to the server, i.e. if you modified iname, groups, …
# File lib/xmpp4r/helpers/roster.rb, line 299
299: def send
300: request = Iq.new_rosterset
301: request.query.add(self)
302: @stream.send(request)
303: end
Send subscription request to the user
The block given to Jabber::Helpers::Roster#add_update_callback will be called, carrying the RosterItem with ask="subscribe"
# File lib/xmpp4r/helpers/roster.rb, line 358
358: def subscribe
359: pres = Presence.new.set_type(:subscribe).set_to(jid)
360: @stream.send(pres)
361: end