diff --git a/src/jcl/jabber/component.py b/src/jcl/jabber/component.py index 43fe59a..1dc1784 100644 --- a/src/jcl/jabber/component.py +++ b/src/jcl/jabber/component.py @@ -573,11 +573,11 @@ class AccountManager(object): return result def send_error_from_account(self, _account, exception): - """Send an error message only one time until _account.in_error - has been reset to False""" + """Send an error message only one time until _account.error + has been reset to None""" result = [] - if _account.in_error == False: - _account.in_error = True + if _account.error == None: + _account.error = str(exception) result.append(Message(from_jid=_account.jid, to_jid=_account.user.jid, stanza_type="error", diff --git a/src/jcl/jabber/presence.py b/src/jcl/jabber/presence.py index 3afafa3..f9be953 100644 --- a/src/jcl/jabber/presence.py +++ b/src/jcl/jabber/presence.py @@ -83,13 +83,14 @@ class AccountPresenceHandler(Handler): class AccountPresenceAvailableHandler(AccountPresenceHandler): def get_account_presence(self, stanza, lang_class, _account): show_status = account.ONLINE - if _account.in_error: + if _account.error is not None: show_status = account.DND elif not _account.enabled: show_status = account.XA - return self.component.account_manager.send_presence_available(_account, - show_status, - lang_class) + return self.component.account_manager.send_presence_available(\ + _account, + show_status, + lang_class) class RootPresenceHandler(AccountPresenceHandler): filter = jabber.get_accounts_root_filter diff --git a/src/jcl/jabber/tests/component.py b/src/jcl/jabber/tests/component.py index 1ce0cd4..bb0f2d9 100644 --- a/src/jcl/jabber/tests/component.py +++ b/src/jcl/jabber/tests/component.py @@ -2781,6 +2781,7 @@ class JCLComponent_TestCase(JCLTestCase): name="account11", jid="account11@jcl.test.com") exception = Exception("test exception") + self.assertEqual(_account.error, None) self.comp.send_error(_account, exception) self.assertEqual(len(self.comp.stream.sent), 1) error_sent = self.comp.stream.sent[0] @@ -2790,6 +2791,7 @@ class JCLComponent_TestCase(JCLTestCase): self.assertEqual(error_sent.get_subject(), _account.default_lang_class.error_subject) self.assertEqual(error_sent.get_body(), _account.default_lang_class.error_body \ % (exception)) + self.assertEqual(_account.error, "test exception") model.db_disconnect() def test_send_error_second(self): @@ -2799,9 +2801,10 @@ class JCLComponent_TestCase(JCLTestCase): _account = Account(user=User(jid="user1@test.com"), name="account11", jid="account11@jcl.test.com") - _account.in_error = True + _account.error = "test exception" exception = Exception("test exception") self.comp.send_error(_account, exception) + self.assertEqual(_account.error, "test exception") self.assertEqual(len(self.comp.stream.sent), 0) def test_send_stanzas(self): diff --git a/src/jcl/jabber/tests/presence.py b/src/jcl/jabber/tests/presence.py index f271285..513fcc5 100644 --- a/src/jcl/jabber/tests/presence.py +++ b/src/jcl/jabber/tests/presence.py @@ -246,7 +246,7 @@ class AccountPresenceAvailableHandler_TestCase(JCLTestCase): account11 = Account(user=user1, name="account11", jid="account11@jcl.test.com") - account11.in_error = True + account11.error = "Error" account12 = Account(user=user1, name="account12", jid="account12@jcl.test.com") diff --git a/src/jcl/model/account.py b/src/jcl/model/account.py index 8326353..d72a2a5 100644 --- a/src/jcl/model/account.py +++ b/src/jcl/model/account.py @@ -91,7 +91,7 @@ class Account(InheritableSQLObject): name = StringCol() jid = StringCol() _status = StringCol(default=OFFLINE, dbName="status") - in_error = BoolCol(default=False) + error = StringCol(default=None) legacy_jids = MultipleJoin('LegacyJID') enabled = BoolCol(default=True) lastlogin = DateTimeCol(default=datetime.datetime.today())