From 2f8c1954f0be9594720eb7637188290cefaaec7d Mon Sep 17 00:00:00 2001 From: Nathan Fritz Date: Tue, 11 May 2010 12:20:57 -0700 Subject: [PATCH 1/2] use pubsub settings --- conn_tests/test_pubsubserver.py | 4 ++-- conn_tests/testconfig.ini | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/conn_tests/test_pubsubserver.py b/conn_tests/test_pubsubserver.py index 9fd3bd8..c9ff900 100644 --- a/conn_tests/test_pubsubserver.py +++ b/conn_tests/test_pubsubserver.py @@ -65,7 +65,7 @@ class TestPubsubServer(unittest.TestCase): """Retrieving node config and reconfiguring""" nconfig = self.xmpp1['xep_0060'].getNodeConfig(self.pshost, 'testnode2') self.failUnless(nconfig, "No configuration returned") - #print("%s == %s" % (nconfig.getValues(), self.statev['defaultconfig'].getValues())) + #print("\n%s ==\n %s" % (nconfig.getValues(), self.statev['defaultconfig'].getValues())) self.failUnless(nconfig.getValues() == self.statev['defaultconfig'].getValues(), "Configuration does not match") self.failUnless(self.xmpp1['xep_0060'].setNodeConfig(self.pshost, 'testnode2', nconfig)) @@ -168,7 +168,7 @@ if __name__ == '__main__': TestPubsubServer.xmpp1 = xmpp1 TestPubsubServer.xmpp2 = xmpp2 - TestPubsubServer.pshost = 'pubsub.recon' + TestPubsubServer.pshost = config.get('settings', 'pubsub') xmpp1.waitforstart.get(True) xmpp2.waitforstart.get(True) testsuite = unittest.TestLoader().loadTestsFromTestCase(TestPubsubServer) diff --git a/conn_tests/testconfig.ini b/conn_tests/testconfig.ini index 91f97a9..fc57bd1 100644 --- a/conn_tests/testconfig.ini +++ b/conn_tests/testconfig.ini @@ -1,5 +1,6 @@ [settings] enabled=true +pubsub=pubsub.recon [account1] jid=fritzy@recon From 8515cef11734613267b1b31f543bca620beac864 Mon Sep 17 00:00:00 2001 From: Nathan Fritz Date: Tue, 11 May 2010 15:12:13 -0700 Subject: [PATCH 2/2] refactored presence tracking and fixed jidInRoom --- sleekxmpp/basexmpp.py | 26 +++++++++++--------------- sleekxmpp/plugins/xep_0045.py | 12 ++++++------ 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/sleekxmpp/basexmpp.py b/sleekxmpp/basexmpp.py index cc0f108..fef8538 100644 --- a/sleekxmpp/basexmpp.py +++ b/sleekxmpp/basexmpp.py @@ -261,27 +261,23 @@ class basexmpp(object): if not presence['from'].bare in self.roster: self.roster[jid] = {'groups': [], 'name': '', 'subscription': 'none', 'presence': {}, 'in_roster': False} if not resource in self.roster[jid]['presence']: + if (show == 'available' or show in presence.showtypes): + self.event("got_online", presence) wasoffline = True - self.roster[jid]['presence'][resource] = {'show': show, 'status': status, 'priority': priority} - else: - if self.roster[jid]['presence'][resource].get('show', 'unavailable') == 'unavailable': - wasoffline = True - self.roster[jid]['presence'][resource] = {'show': show, 'status': status} - self.roster[jid]['presence'][resource]['priority'] = priority + self.roster[jid]['presence'][resource] = {} + if self.roster[jid]['presence'][resource].get('show', 'unavailable') == 'unavailable': + wasoffline = True + self.roster[jid]['presence'][resource] = {'show': show, 'status': status, 'priority': priority} name = self.roster[jid].get('name', '') - if wasoffline and (show == 'available' or show in presence.showtypes): - self.event("got_online", presence) - self.event("changed_status", presence) - elif show == 'unavailable': + if show == 'unavailable': logging.debug("%s %s got offline" % (jid, resource)) - if len(self.roster[jid]['presence']) > 1: + if len(self.roster[jid]['presence']): del self.roster[jid]['presence'][resource] else: del self.roster[jid] - self.event("got_offline", presence) - self.event("changed_status", presence) - elif oldroster != self.roster.get(jid, {'presence': {}})['presence'].get(resource, {}): - self.event("changed_status", presence) + if not wasoffline: + self.event("got_offline", presence) + self.event("changed_status", presence) name = '' if name: name = "(%s) " % name diff --git a/sleekxmpp/plugins/xep_0045.py b/sleekxmpp/plugins/xep_0045.py index 7fc8a2b..240e6b9 100644 --- a/sleekxmpp/plugins/xep_0045.py +++ b/sleekxmpp/plugins/xep_0045.py @@ -147,12 +147,12 @@ class xep_0045(base.base_plugin): """ self.xmpp.event('groupchat_message', msg) - def jidInRoom(self, room, jid): - for nick in self.rooms[room]: - entry = self.rooms[room][nick] - if entry is not None and entry['jid'].full == jid: - return True - return False + def jidInRoom(self, room, jid): + for nick in self.rooms[room]: + entry = self.rooms[room][nick] + if entry is not None and entry['jid'].full == jid: + return True + return False def getRoomForm(self, room, ifrom=None): iq = self.xmpp.makeIqGet()