# HG changeset patch # User Goffi # Date 1486302921 -3600 # Node ID c0577837680a0df222f0246504c1d324947e6f06 # Parent 628c1c95f44255ef3e98ed693e40a46f6b282bb7 core: replaced SkipHistory exception by a key in mess_data: SkipHistory was skipping all remaining triggers just to skip history, which is not the intented behaviour. Now history can be skipped by setting mess_data[u'history'] = C.HISTORY_SKIP, this way we won't skip importants triggers. When history is skipped, mess_data[u'extra'][u'history'] will be set to C.HISTORY_SKIP for frontends, so they can inform user that the message is not stored locally. diff -r 628c1c95f442 -r c0577837680a src/core/constants.py --- a/src/core/constants.py Sun Feb 05 14:55:19 2017 +0100 +++ b/src/core/constants.py Sun Feb 05 14:55:21 2017 +0100 @@ -37,6 +37,7 @@ ## Runtime ## PLUGIN_EXT = "py" + HISTORY_SKIP = u'skip' ## Main config ## DEFAULT_BRIDGE = 'dbus' diff -r 628c1c95f442 -r c0577837680a src/core/exceptions.py --- a/src/core/exceptions.py Sun Feb 05 14:55:19 2017 +0100 +++ b/src/core/exceptions.py Sun Feb 05 14:55:21 2017 +0100 @@ -108,10 +108,6 @@ pass -class SkipHistory(Exception): # used in MessageReceivedTrigger to avoid history writting - pass - - class ParsingError(Exception): pass diff -r 628c1c95f442 -r c0577837680a src/core/xmpp.py --- a/src/core/xmpp.py Sun Feb 05 14:55:19 2017 +0100 +++ b/src/core/xmpp.py Sun Feb 05 14:55:21 2017 +0100 @@ -234,7 +234,6 @@ post_treat.addCallback(self.skipEmptyMessage) post_treat.addCallback(self.addToHistory, client) - post_treat.addErrback(self.treatmentsEb) post_treat.addCallback(self.bridgeSignal, client, data) post_treat.addErrback(self.cancelErrorTrap) post_treat.callback(data) @@ -245,10 +244,11 @@ return data def addToHistory(self, data, client): - return self.host.memory.addToHistory(client, data) - - def treatmentsEb(self, failure_): - failure_.trap(exceptions.SkipHistory) + if data.pop(u'history', None) == C.HISTORY_SKIP: + log.info(u'history is skipped as requested') + data[u'extra'][u'history'] = C.HISTORY_SKIP + else: + return self.host.memory.addToHistory(client, data) def bridgeSignal(self, dummy, client, data): try: diff -r 628c1c95f442 -r c0577837680a src/plugins/plugin_sec_otr.py --- a/src/plugins/plugin_sec_otr.py Sun Feb 05 14:55:19 2017 +0100 +++ b/src/plugins/plugin_sec_otr.py Sun Feb 05 14:55:21 2017 +0100 @@ -463,8 +463,13 @@ # decrypted messages handling. # receiveMessage() will return a tuple, the first part of which will be the decrypted message data['message'] = {'':res[0].decode('utf-8')} # FIXME: Q&D fix for message refactoring, message is now a dict + try: + # we want to keep message in history, even if no store is requested in message hints + del message[u'history'] + except KeyError: + pass # TODO: add skip history as an option, but by default we don't skip it - # raise failure.Failure(exceptions.SkipHistory()) # we send the decrypted message to frontends, but we don't want it in history + # data[u'history'] = C.HISTORY_SKIP # we send the decrypted message to frontends, but we don't want it in history else: log.warning(u"An encrypted message was expected, but got {}".format(data['message'])) raise failure.Failure(exceptions.CancelError('Cancelled by OTR')) # no message at all (no history, no signal) @@ -481,7 +486,11 @@ except StopIteration: return data if message.startswith(potr.proto.OTRTAG): - raise failure.Failure(exceptions.SkipHistory()) + # FIXME: it may be better to cancel the message and send it direclty to bridge + # this is used by Libervia, but this may send garbage message to other frontends + # if they are used at the same time as Libervia. + # Hard to avoid with decryption on Libervia though. + data[u'history'] = C.HISTORY_SKIP return data def MessageReceivedTrigger(self, client, message_elt, post_treat): diff -r 628c1c95f442 -r c0577837680a src/plugins/plugin_xep_0334.py --- a/src/plugins/plugin_xep_0334.py Sun Feb 05 14:55:19 2017 +0100 +++ b/src/plugins/plugin_xep_0334.py Sun Feb 05 14:55:21 2017 +0100 @@ -21,8 +21,8 @@ from sat.core.i18n import _, D_ from sat.core.log import getLogger log = getLogger(__name__) +from sat.core.constants import Const as C -from sat.core import exceptions from sat.tools.common import data_format from wokkel import disco, iwokkel @@ -30,7 +30,6 @@ from twisted.words.protocols.xmlstream import XMPPHandler except ImportError: from wokkel.subprotocols import XMPPHandler -from twisted.python import failure from zope.interface import implements from textwrap import dedent @@ -95,9 +94,8 @@ return True def _receivedSkipHistory(self, mess_data): - mess_data[u'extra'][u'history'] == u'skipped' - raise failure.Failure(exceptions.SkipHistory()) - + mess_data[u'history'] = C.HISTORY_SKIP + return mess_data def messageReceivedTrigger(self, client, message_elt, post_treat): """Check for hints in the received message"""