mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-23 19:19:53 +00:00
Add some convenience methods to rosters.
Can now use len(self.client_roster) to get the number of JIDs in the roster, and self.client_roster.groups() to get a dict of groups and the JIDs in those groups.
This commit is contained in:
parent
004eabf809
commit
3fc20e10f5
1 changed files with 14 additions and 0 deletions
|
@ -75,6 +75,10 @@ class RosterNode(object):
|
|||
self.add(key, save=True)
|
||||
return self._jids[key]
|
||||
|
||||
def __len__(self):
|
||||
"""Return the number of JIDs referenced by the roster."""
|
||||
return len(self._jids)
|
||||
|
||||
def keys(self):
|
||||
"""Return a list of all subscribed JIDs."""
|
||||
return self._jids.keys()
|
||||
|
@ -83,6 +87,16 @@ class RosterNode(object):
|
|||
"""Returns whether the roster has a JID."""
|
||||
return jid in self._jids
|
||||
|
||||
def groups(self):
|
||||
"""Return a dictionary mapping group names to JIDs."""
|
||||
result = {}
|
||||
for jid in self._jids:
|
||||
for group in self._jids[jid]['groups']:
|
||||
if group not in result:
|
||||
result[group] = []
|
||||
result[group].append(jid)
|
||||
return result
|
||||
|
||||
def __iter__(self):
|
||||
"""Iterate over the roster items."""
|
||||
return self._jids.__iter__()
|
||||
|
|
Loading…
Reference in a new issue