fixed bug #16 Roster not updating

This commit is contained in:
Nathan Fritz 2010-03-26 13:55:03 -07:00
parent 0659ddeff0
commit 0fc9072e5d
2 changed files with 14 additions and 10 deletions

View file

@ -163,7 +163,8 @@ class ClientXMPP(basexmpp, XMLStream):
def getRoster(self): def getRoster(self):
"""Request the roster be sent.""" """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): def _handleStreamFeatures(self, features):
self.features = [] self.features = []
@ -245,11 +246,12 @@ class ClientXMPP(basexmpp, XMLStream):
self.sessionstarted = True self.sessionstarted = True
self.event("session_start") self.event("session_start")
def _handleRoster(self, iq): def _handleRoster(self, iq, request=False):
for jid in iq['roster']['items']: if iq['type'] == 'set' or (iq['type'] == 'result' and request):
if not jid.bare in self.roster: for jid in iq['roster']['items']:
self.roster[jid.bare] = {'groups': [], 'name': '', 'subscription': 'none', 'presence': {}, 'in_roster': True} if not jid in self.roster:
self.roster[jid.bare].update(iq['roster']['jid']) self.roster[jid] = {'groups': [], 'name': '', 'subscription': 'none', 'presence': {}, 'in_roster': True}
if iq['type'] == 'set': self.roster[jid].update(iq['roster']['items'][jid])
self.send(self.Iq().setValues({'type': 'result', 'id': iq['id']}).enable('roster')) if iq['type'] == 'set':
self.send(self.Iq().setValues({'type': 'result', 'id': iq['id']}).enable('roster'))
self.event("roster_update", iq) self.event("roster_update", iq)

View file

@ -1,10 +1,12 @@
from .. xmlstream.stanzabase import ElementBase, ET, JID from .. xmlstream.stanzabase import ElementBase, ET, JID
import logging
class Roster(ElementBase): class Roster(ElementBase):
namespace = 'jabber:iq:roster' namespace = 'jabber:iq:roster'
name = 'query' name = 'query'
plugin_attrib = 'roster' plugin_attrib = 'roster'
interfaces = set(('items',)) interfaces = set(('items',))
sub_interfaces = set()
def setItems(self, items): def setItems(self, items):
self.delItems() self.delItems()
@ -27,8 +29,8 @@ class Roster(ElementBase):
items = {} items = {}
itemsxml = self.xml.findall('{jabber:iq:roster}item') itemsxml = self.xml.findall('{jabber:iq:roster}item')
if itemsxml is not None: if itemsxml is not None:
item = {}
for itemxml in itemsxml: for itemxml in itemsxml:
item = {}
item['name'] = itemxml.get('name', '') item['name'] = itemxml.get('name', '')
item['subscription'] = itemxml.get('subscription', '') item['subscription'] = itemxml.get('subscription', '')
item['groups'] = [] item['groups'] = []
@ -36,7 +38,7 @@ class Roster(ElementBase):
if groupsxml is not None: if groupsxml is not None:
for groupxml in groupsxml: for groupxml in groupsxml:
item['groups'].append(groupxml.text) item['groups'].append(groupxml.text)
items[JID(itemxml.get('jid'))] = item items[itemxml.get('jid')] = item
return items return items
def delItems(self): def delItems(self):