diff options
-rw-r--r-- | sleekxmpp/__init__.py | 18 | ||||
-rw-r--r-- | sleekxmpp/stanza/roster.py | 6 |
2 files changed, 14 insertions, 10 deletions
diff --git a/sleekxmpp/__init__.py b/sleekxmpp/__init__.py index b81e8a13..8452e65d 100644 --- a/sleekxmpp/__init__.py +++ b/sleekxmpp/__init__.py @@ -163,7 +163,8 @@ class ClientXMPP(basexmpp, XMLStream): def getRoster(self): """Request the roster be sent.""" - self.Iq().setValues({'type': 'get'}).enable('roster').send() + iq = self.Iq().setValues({'type': 'get'}).enable('roster').send() + self._handleRoster(iq, request=True) def _handleStreamFeatures(self, features): self.features = [] @@ -245,11 +246,12 @@ class ClientXMPP(basexmpp, XMLStream): self.sessionstarted = True self.event("session_start") - def _handleRoster(self, iq): - for jid in iq['roster']['items']: - if not jid.bare in self.roster: - self.roster[jid.bare] = {'groups': [], 'name': '', 'subscription': 'none', 'presence': {}, 'in_roster': True} - self.roster[jid.bare].update(iq['roster']['jid']) - if iq['type'] == 'set': - self.send(self.Iq().setValues({'type': 'result', 'id': iq['id']}).enable('roster')) + def _handleRoster(self, iq, request=False): + if iq['type'] == 'set' or (iq['type'] == 'result' and request): + for jid in iq['roster']['items']: + if not jid in self.roster: + self.roster[jid] = {'groups': [], 'name': '', 'subscription': 'none', 'presence': {}, 'in_roster': True} + self.roster[jid].update(iq['roster']['items'][jid]) + if iq['type'] == 'set': + self.send(self.Iq().setValues({'type': 'result', 'id': iq['id']}).enable('roster')) self.event("roster_update", iq) diff --git a/sleekxmpp/stanza/roster.py b/sleekxmpp/stanza/roster.py index 21aaa161..d8b61a5b 100644 --- a/sleekxmpp/stanza/roster.py +++ b/sleekxmpp/stanza/roster.py @@ -1,10 +1,12 @@ from .. xmlstream.stanzabase import ElementBase, ET, JID +import logging class Roster(ElementBase): namespace = 'jabber:iq:roster' name = 'query' plugin_attrib = 'roster' interfaces = set(('items',)) + sub_interfaces = set() def setItems(self, items): self.delItems() @@ -27,8 +29,8 @@ class Roster(ElementBase): items = {} itemsxml = self.xml.findall('{jabber:iq:roster}item') if itemsxml is not None: - item = {} for itemxml in itemsxml: + item = {} item['name'] = itemxml.get('name', '') item['subscription'] = itemxml.get('subscription', '') item['groups'] = [] @@ -36,7 +38,7 @@ class Roster(ElementBase): if groupsxml is not None: for groupxml in groupsxml: item['groups'].append(groupxml.text) - items[JID(itemxml.get('jid'))] = item + items[itemxml.get('jid')] = item return items def delItems(self): |