mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-23 19:19:53 +00:00
fixed bug #16 Roster not updating
This commit is contained in:
parent
0659ddeff0
commit
0fc9072e5d
2 changed files with 14 additions and 10 deletions
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue