summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sleekxmpp/basexmpp.py7
-rw-r--r--tests/test_presencestanzas.py16
2 files changed, 20 insertions, 3 deletions
diff --git a/sleekxmpp/basexmpp.py b/sleekxmpp/basexmpp.py
index fef8538a..13fe2100 100644
--- a/sleekxmpp/basexmpp.py
+++ b/sleekxmpp/basexmpp.py
@@ -271,12 +271,13 @@ class basexmpp(object):
name = self.roster[jid].get('name', '')
if show == 'unavailable':
logging.debug("%s %s got offline" % (jid, resource))
- if len(self.roster[jid]['presence']):
- del self.roster[jid]['presence'][resource]
- else:
+ del self.roster[jid]['presence'][resource]
+ if len(self.roster[jid]['presence']) == 0 and not self.roster[jid]['in_roster']:
del self.roster[jid]
if not wasoffline:
self.event("got_offline", presence)
+ else:
+ return False
self.event("changed_status", presence)
name = ''
if name:
diff --git a/tests/test_presencestanzas.py b/tests/test_presencestanzas.py
index 430c71ca..23eb911e 100644
--- a/tests/test_presencestanzas.py
+++ b/tests/test_presencestanzas.py
@@ -11,5 +11,21 @@ class testpresencestanzas(unittest.TestCase):
p = self.p.Presence()
p['type'] = 'dnd'
self.failUnless(str(p) == "<presence><show>dnd</show></presence>")
+
+ def testPresenceUnsolicitedOffline(self):
+ "Unsolicted offline presence does not spawn changed_status or update roster"
+ p = self.p.Presence()
+ p['type'] = 'unavailable'
+ p['from'] = 'bill@chadmore.com/gmail15af'
+ import sleekxmpp
+ c = sleekxmpp.ClientXMPP('crap@wherever', 'password')
+ happened = []
+ def handlechangedpresence(event):
+ happened.append(True)
+ c.add_event_handler("changed_status", handlechangedpresence)
+ c._handlePresence(p)
+ self.failUnless(happened == [], "changed_status event triggered for superfulous unavailable presence")
+ self.failUnless(c.roster == {}, "Roster updated for superfulous unavailable presence")
+
suite = unittest.TestLoader().loadTestsFromTestCase(testpresencestanzas)