| Class | Jabber::Roster::IqQueryRoster |
| In: |
lib/xmpp4r/roster/iq/roster.rb
|
| Parent: | IqQuery |
Class for handling roster updates
You must do ‘client.send(Iq.new_rosterget)’ or else you will have nothing to put in receive_iq()
You must require ‘xmpp4r/rosterquery’ to use this class as its functionality is not needed for a working XMPP implementation. This will make [IqQuery] convert all Queries with namespace ‘jabber:iq:roster’ to [IqQueryRoster]
This <query/> contains multiple <item/> children. See RosterItem.
Get roster item by JID
| jid: | [JID] or [Nil] |
| result: | [RosterItem] |
# File lib/xmpp4r/roster/iq/roster.rb, line 60
60: def [](jid)
61: each { |item|
62: return(item) if item.jid == jid
63: }
64: nil
65: end
Iterate through all items
| &block: | Yield for every [RosterItem] |
# File lib/xmpp4r/roster/iq/roster.rb, line 49
49: def each(&block)
50: each_element { |item|
51: # XPath won't work here as it's missing a prefix...
52: yield(item) if item.kind_of?(RosterItem)
53: }
54: end
Output for "p"
JIDs of all contained [RosterItem] elements are joined with a comma
| result: | [String] |
# File lib/xmpp4r/roster/iq/roster.rb, line 96
96: def inspect
97: jids = to_a.collect { |item| item.jid.inspect }
98: jids.join(', ')
99: end
Update roster by <iq/> stanza (to be fed by an iq_callback)
| iq: | [Iq] Containing new roster |
| filter: | [Boolean] If false import non-roster-like results too |
# File lib/xmpp4r/roster/iq/roster.rb, line 83
83: def receive_iq(iq, filter=true)
84: if filter && (((iq.type != :set) && (iq.type != :result)) || (iq.queryns != 'jabber:iq:roster'))
85: return
86: end
87:
88: import(iq.query)
89: end
Get all items
| result: | [Array] of [RosterItem] |
# File lib/xmpp4r/roster/iq/roster.rb, line 70
70: def to_a
71: a = []
72: each { |item|
73: a.push(item)
74: }
75: a
76: end
Add an element to the roster
Converts <item/> elements to RosterItem
Previous RosterItems with the same JID will not be deleted!
# File lib/xmpp4r/roster/iq/roster.rb, line 37
37: def typed_add(element)
38: if element.kind_of?(REXML::Element) && (element.name == 'item')
39: item = RosterItem::new.import(element)
40: super(item)
41: else
42: super(element)
43: end
44: end