comparison src/plugins/plugin_xep_0334.py @ 2132:c0577837680a

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.
author Goffi <goffi@goffi.org>
date Sun, 05 Feb 2017 14:55:21 +0100
parents 628c1c95f442
children 1d3f73e065e1
comparison
equal deleted inserted replaced
2131:628c1c95f442 2132:c0577837680a
19 # along with this program. If not, see <http://www.gnu.org/licenses/>. 19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 20
21 from sat.core.i18n import _, D_ 21 from sat.core.i18n import _, D_
22 from sat.core.log import getLogger 22 from sat.core.log import getLogger
23 log = getLogger(__name__) 23 log = getLogger(__name__)
24 from sat.core.constants import Const as C
24 25
25 from sat.core import exceptions
26 from sat.tools.common import data_format 26 from sat.tools.common import data_format
27 27
28 from wokkel import disco, iwokkel 28 from wokkel import disco, iwokkel
29 try: 29 try:
30 from twisted.words.protocols.xmlstream import XMPPHandler 30 from twisted.words.protocols.xmlstream import XMPPHandler
31 except ImportError: 31 except ImportError:
32 from wokkel.subprotocols import XMPPHandler 32 from wokkel.subprotocols import XMPPHandler
33 from twisted.python import failure
34 from zope.interface import implements 33 from zope.interface import implements
35 from textwrap import dedent 34 from textwrap import dedent
36 35
37 36
38 PLUGIN_INFO = { 37 PLUGIN_INFO = {
93 92
94 post_xml_treatments.addCallback(self._sendPostXmlTreatment) 93 post_xml_treatments.addCallback(self._sendPostXmlTreatment)
95 return True 94 return True
96 95
97 def _receivedSkipHistory(self, mess_data): 96 def _receivedSkipHistory(self, mess_data):
98 mess_data[u'extra'][u'history'] == u'skipped' 97 mess_data[u'history'] = C.HISTORY_SKIP
99 raise failure.Failure(exceptions.SkipHistory()) 98 return mess_data
100
101 99
102 def messageReceivedTrigger(self, client, message_elt, post_treat): 100 def messageReceivedTrigger(self, client, message_elt, post_treat):
103 """Check for hints in the received message""" 101 """Check for hints in the received message"""
104 for elt in message_elt.elements(): 102 for elt in message_elt.elements():
105 if elt.uri == NS_HINTS and elt.name in (self.HINT_NO_PERMANENT_STORE, self.HINT_NO_STORE): 103 if elt.uri == NS_HINTS and elt.name in (self.HINT_NO_PERMANENT_STORE, self.HINT_NO_STORE):