Reset the roster on disconnect instead of replacing it.

This commit is contained in:
Lance Stout 2011-02-14 16:24:49 -05:00
parent a278f79bdb
commit e4f3b777f9
2 changed files with 25 additions and 1 deletions

View file

@ -595,7 +595,7 @@ class BaseXMPP(XMLStream):
def _handle_disconnected(self, event): def _handle_disconnected(self, event):
"""When disconnected, reset the roster""" """When disconnected, reset the roster"""
self.roster = {} self.roster.reset()
def _handle_stream_error(self, error): def _handle_stream_error(self, error):
self.event('stream_error', error) self.event('stream_error', error)

View file

@ -105,6 +105,14 @@ class Roster(object):
for node in self._rosters: for node in self._rosters:
self._rosters[node].set_backend(db) self._rosters[node].set_backend(db)
def reset(self):
"""
Reset the state of the roster to forget any current
presence information. Useful after a disconnection occurs.
"""
for node in self:
self[node].reset()
class RosterNode(object): class RosterNode(object):
@ -305,6 +313,15 @@ class RosterNode(object):
return self[jid].resources.get(resource, return self[jid].resources.get(resource,
default_presence) default_presence)
def reset(self):
"""
Reset the state of the roster to forget any current
presence information. Useful after a disconnection occurs.
"""
for jid in self:
self[jid].reset()
class RosterItem(object): class RosterItem(object):
@ -725,3 +742,10 @@ class RosterItem(object):
self.subscribe() self.subscribe()
if not self['to']: if not self['to']:
self._unsubscribed() self._unsubscribed()
def reset(self):
"""
Forgot current resource presence information as part of
a roster reset request.
"""
self.resources = {}