diff --git a/src/jcl/jabber/component.py b/src/jcl/jabber/component.py index 43d6f9c..4b03925 100644 --- a/src/jcl/jabber/component.py +++ b/src/jcl/jabber/component.py @@ -387,25 +387,24 @@ class AccountManager(object): """Send available presence to account's user and ask for password if necessary""" result = [] - model.db_connect() old_status = _account.status _account.status = account.ONLINE if _account.error is not None: _account.status = account.DND elif not _account.enabled: _account.status = account.XA - result.extend(self.get_presence(from_jid=_account.jid, - to_jid=_account.user.jid, - status=_account.status_msg, - show=_account.status, - presence_type="available")) + if old_status != _account.status: + result.extend(self.get_presence(from_jid=_account.jid, + to_jid=_account.user.jid, + status=_account.status_msg, + show=_account.status, + presence_type="available")) if hasattr(_account, 'store_password') \ and hasattr(_account, 'password') \ and _account.store_password == False \ and old_status == account.OFFLINE \ and _account.password == None : result.extend(self.ask_password(_account, lang_class)) - model.db_disconnect() return result def probe_all_accounts_presence(self): diff --git a/src/jcl/jabber/tests/component.py b/src/jcl/jabber/tests/component.py index 59127ef..e7c5fbc 100644 --- a/src/jcl/jabber/tests/component.py +++ b/src/jcl/jabber/tests/component.py @@ -3189,6 +3189,16 @@ class AccountManager_TestCase(JCLTestCase): self.assertEquals(presence.children.name, "show") self.assertEquals(presence.children.content, "online") + def test_get_account_presence_available_no_change(self): + """Test when presence status does not change""" + _account = Account(user=User(jid="user1@test.com"), + name="account11", + jid="account11@jcl.test.com") + _account.status = account.ONLINE + result = self.account_manager.get_account_presence_available(\ + _account, _account.default_lang_class) + self.assertEquals(len(result), 0) + def suite(): test_suite = unittest.TestSuite() test_suite.addTest(unittest.makeSuite(JCLComponent_TestCase, 'test'))