Integrate roster with ClientXMPP.

Roster updates are now passed through to the roster when using
self.update_roster, etc.
This commit is contained in:
Lance Stout 2011-06-16 16:09:15 -07:00
parent 29d775e675
commit ce145b04ac
2 changed files with 18 additions and 13 deletions

View file

@ -225,15 +225,8 @@ class ClientXMPP(BaseXMPP):
Will be executed when the roster is received. Will be executed when the roster is received.
Implies block=False. Implies block=False.
""" """
iq = self.Iq() return self.client_roster.updtae(jid, name, subscription, groups,
iq['type'] = 'set' block, timeout, callback)
iq['roster']['items'] = {jid: {'name': name,
'subscription': subscription,
'groups': groups}}
response = iq.send(block, timeout, callback)
if response in [False, None] or not isinstance(response, Iq):
return response
return response['type'] == 'result'
def del_roster_item(self, jid): def del_roster_item(self, jid):
""" """
@ -243,7 +236,7 @@ class ClientXMPP(BaseXMPP):
Arguments: Arguments:
jid -- The JID of the item to remove. jid -- The JID of the item to remove.
""" """
return self.update_roster(jid, subscription='remove') return self.client_roster.remove(jid)
def get_roster(self, block=True, timeout=None, callback=None): def get_roster(self, block=True, timeout=None, callback=None):
""" """

View file

@ -171,9 +171,10 @@ class RosterNode(object):
""" """
self[jid].remove() self[jid].remove()
if not self.xmpp.is_component: if not self.xmpp.is_component:
self.update(jid, subscription='remove') return self.update(jid, subscription='remove')
def update(self, jid, name=None, subscription=None, groups=[]): def update(self, jid, name=None, subscription=None, groups=[],
block=True, timeout=None, callback=None):
""" """
Update a JID's subscription information. Update a JID's subscription information.
@ -183,6 +184,15 @@ class RosterNode(object):
subscription -- The subscription state. May be one of: 'to', subscription -- The subscription state. May be one of: 'to',
'from', 'both', 'none', or 'remove'. 'from', 'both', 'none', or 'remove'.
groups -- A list of group names. groups -- A list of group names.
block -- Specify if the roster request will block
until a response is received, or a timeout
occurs. Defaults to True.
timeout -- The length of time (in seconds) to wait
for a response before continuing if blocking
is used. Defaults to self.response_timeout.
callback -- Optional reference to a stream handler function.
Will be executed when the roster is received.
Implies block=False.
""" """
self[jid]['name'] = name self[jid]['name'] = name
self[jid]['groups'] = group self[jid]['groups'] = group
@ -194,7 +204,9 @@ class RosterNode(object):
iq['roster']['items'] = {jid: {'name': name, iq['roster']['items'] = {jid: {'name': name,
'subscription': subscription, 'subscription': subscription,
'groups': groups}} 'groups': groups}}
response = iq.send() response = iq.send(block, timeout, callback)
if response in [False, None] or isinstance(response, Iq):
return response
return response and response['type'] == 'result' return response and response['type'] == 'result'
def presence(self, jid, resource=None): def presence(self, jid, resource=None):