mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-23 19:19:53 +00:00
Fix changed_status event
Once again only fires when a resource's presence show value changes.
This commit is contained in:
parent
2de1be188c
commit
22868c3924
3 changed files with 98 additions and 2 deletions
|
@ -778,8 +778,6 @@ class BaseXMPP(XMLStream):
|
|||
not presence['type'] in presence.showtypes:
|
||||
return
|
||||
|
||||
self.event("changed_status", presence)
|
||||
|
||||
def exception(self, exception):
|
||||
"""
|
||||
Process any uncaught exceptions, notably IqError and
|
||||
|
|
|
@ -345,7 +345,10 @@ class RosterItem(object):
|
|||
self.xmpp.event('got_online', presence)
|
||||
if resource not in self.resources:
|
||||
self.resources[resource] = {}
|
||||
old_show = self.resources[resource].get('show', None)
|
||||
self.resources[resource].update(data)
|
||||
if old_show != presence['show']:
|
||||
self.xmpp.event('changed_status', presence)
|
||||
|
||||
def handle_unavailable(self, presence):
|
||||
resource = presence['from'].resource
|
||||
|
@ -353,6 +356,7 @@ class RosterItem(object):
|
|||
return
|
||||
if resource in self.resources:
|
||||
del self.resources[resource]
|
||||
self.xmpp.event('changed_status', presence)
|
||||
if not self.resources:
|
||||
self.xmpp.event('got_offline', presence)
|
||||
|
||||
|
|
|
@ -251,5 +251,99 @@ class TestStreamPresence(SleekTest):
|
|||
self.assertEqual(events, ptypes,
|
||||
"Not all events raised: %s" % events)
|
||||
|
||||
def test_changed_status(self):
|
||||
"""Test that the changed_status event is handled properly."""
|
||||
events = []
|
||||
self.stream_start()
|
||||
|
||||
def changed_status(presence):
|
||||
events.append(presence['type'])
|
||||
|
||||
self.xmpp.add_event_handler('changed_status', changed_status)
|
||||
|
||||
self.recv("""
|
||||
<presence from="user@example.com" to="tester@localhost" />
|
||||
""")
|
||||
|
||||
self.recv("""
|
||||
<presence from="user@example.com" to="tester@localhost" />
|
||||
""")
|
||||
|
||||
self.recv("""
|
||||
<presence from="user@example.com" to="tester@localhost">
|
||||
<show>away</show>
|
||||
</presence>
|
||||
""")
|
||||
|
||||
self.recv("""
|
||||
<presence from="user@example.com" to="tester@localhost">
|
||||
<show>away</show>
|
||||
</presence>
|
||||
""")
|
||||
|
||||
self.recv("""
|
||||
<presence from="user@example.com" to="tester@localhost">
|
||||
<show>dnd</show>
|
||||
</presence>
|
||||
""")
|
||||
|
||||
self.recv("""
|
||||
<presence from="user@example.com" to="tester@localhost">
|
||||
<show>dnd</show>
|
||||
</presence>
|
||||
""")
|
||||
|
||||
self.recv("""
|
||||
<presence from="user@example.com" to="tester@localhost">
|
||||
<show>chat</show>
|
||||
</presence>
|
||||
""")
|
||||
|
||||
self.recv("""
|
||||
<presence from="user@example.com" to="tester@localhost">
|
||||
<show>chat</show>
|
||||
</presence>
|
||||
""")
|
||||
|
||||
self.recv("""
|
||||
<presence from="user@example.com" to="tester@localhost">
|
||||
<show>xa</show>
|
||||
</presence>
|
||||
""")
|
||||
|
||||
self.recv("""
|
||||
<presence from="user@example.com" to="tester@localhost">
|
||||
<show>xa</show>
|
||||
</presence>
|
||||
""")
|
||||
|
||||
self.recv("""
|
||||
<presence from="user@example.com"
|
||||
to="tester@localhost"
|
||||
type="unavailable" />
|
||||
""")
|
||||
|
||||
self.recv("""
|
||||
<presence from="user@example.com"
|
||||
to="tester@localhost"
|
||||
type="unavailable" />
|
||||
""")
|
||||
|
||||
self.recv("""
|
||||
<presence from="user@example.com" to="tester@localhost" />
|
||||
""")
|
||||
|
||||
self.recv("""
|
||||
<presence from="user@example.com" to="tester@localhost" />
|
||||
""")
|
||||
|
||||
|
||||
time.sleep(0.3)
|
||||
|
||||
self.assertEqual(events, ['available', 'away', 'dnd', 'chat',
|
||||
'xa', 'unavailable', 'available'],
|
||||
"Changed status events incorrect: %s" % events)
|
||||
|
||||
|
||||
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamPresence)
|
||||
|
|
Loading…
Reference in a new issue