From e4f3b777f9d6c57a2d05296079828609e6b18375 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Mon, 14 Feb 2011 16:24:49 -0500 Subject: Reset the roster on disconnect instead of replacing it. --- sleekxmpp/basexmpp.py | 2 +- sleekxmpp/roster.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/sleekxmpp/basexmpp.py b/sleekxmpp/basexmpp.py index 460c01f3..4391ff48 100644 --- a/sleekxmpp/basexmpp.py +++ b/sleekxmpp/basexmpp.py @@ -595,7 +595,7 @@ class BaseXMPP(XMLStream): def _handle_disconnected(self, event): """When disconnected, reset the roster""" - self.roster = {} + self.roster.reset() def _handle_stream_error(self, error): self.event('stream_error', error) diff --git a/sleekxmpp/roster.py b/sleekxmpp/roster.py index 60a13c11..043981e3 100644 --- a/sleekxmpp/roster.py +++ b/sleekxmpp/roster.py @@ -105,6 +105,14 @@ class Roster(object): for node in self._rosters: 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): @@ -305,6 +313,15 @@ class RosterNode(object): return self[jid].resources.get(resource, 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): @@ -725,3 +742,10 @@ class RosterItem(object): self.subscribe() if not self['to']: self._unsubscribed() + + def reset(self): + """ + Forgot current resource presence information as part of + a roster reset request. + """ + self.resources = {} -- cgit v1.2.3