diff src/plugins/plugin_sec_otr.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 6a66c8c5a567
children 6e509ee853a8
line wrap: on
line diff
--- 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):