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!

Methods

Attributes

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

Public Class methods

Initialize an empty RosterItem

[Source]

     # File lib/xmpp4r/helpers/roster.rb, line 276
276:       def initialize(stream)
277:         super()
278:         @stream = stream
279:         @presences = []
280:       end

Public Instance methods

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.

[Source]

     # 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

[Source]

     # 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

[Source]

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

[Source]

     # File lib/xmpp4r/helpers/roster.rb, line 310
310:       def online?
311:         @presences.size > 0
312:       end

Get specific presence

jid:[JID] Full JID

[Source]

     # File lib/xmpp4r/helpers/roster.rb, line 325
325:       def presence(jid)
326:         @presences.each do |pres|
327:           if pres.from == jid
328:             return(pres)
329:           end
330:         end
331:         nil
332:       end

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

[Source]

     # 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"

[Source]

     # 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

Send unsubscription request to the user

[Source]

     # File lib/xmpp4r/helpers/roster.rb, line 365
365:       def unsubscribe
366:         pres = Presence.new.set_type(:unsubscribe).set_to(jid)
367:         @stream.send(pres)
368:       end

[Validate]