comparison 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
comparison
equal deleted inserted replaced
2131:628c1c95f442 2132:c0577837680a
461 if encrypted: 461 if encrypted:
462 if res[0] != None: 462 if res[0] != None:
463 # decrypted messages handling. 463 # decrypted messages handling.
464 # receiveMessage() will return a tuple, the first part of which will be the decrypted message 464 # receiveMessage() will return a tuple, the first part of which will be the decrypted message
465 data['message'] = {'':res[0].decode('utf-8')} # FIXME: Q&D fix for message refactoring, message is now a dict 465 data['message'] = {'':res[0].decode('utf-8')} # FIXME: Q&D fix for message refactoring, message is now a dict
466 try:
467 # we want to keep message in history, even if no store is requested in message hints
468 del message[u'history']
469 except KeyError:
470 pass
466 # TODO: add skip history as an option, but by default we don't skip it 471 # TODO: add skip history as an option, but by default we don't skip it
467 # raise failure.Failure(exceptions.SkipHistory()) # we send the decrypted message to frontends, but we don't want it in history 472 # data[u'history'] = C.HISTORY_SKIP # we send the decrypted message to frontends, but we don't want it in history
468 else: 473 else:
469 log.warning(u"An encrypted message was expected, but got {}".format(data['message'])) 474 log.warning(u"An encrypted message was expected, but got {}".format(data['message']))
470 raise failure.Failure(exceptions.CancelError('Cancelled by OTR')) # no message at all (no history, no signal) 475 raise failure.Failure(exceptions.CancelError('Cancelled by OTR')) # no message at all (no history, no signal)
471 return data 476 return data
472 477
479 try: 484 try:
480 message = data['message'].itervalues().next().encode('utf-8') # FIXME: Q&D fix for message refactoring, message is now a dict 485 message = data['message'].itervalues().next().encode('utf-8') # FIXME: Q&D fix for message refactoring, message is now a dict
481 except StopIteration: 486 except StopIteration:
482 return data 487 return data
483 if message.startswith(potr.proto.OTRTAG): 488 if message.startswith(potr.proto.OTRTAG):
484 raise failure.Failure(exceptions.SkipHistory()) 489 # FIXME: it may be better to cancel the message and send it direclty to bridge
490 # this is used by Libervia, but this may send garbage message to other frontends
491 # if they are used at the same time as Libervia.
492 # Hard to avoid with decryption on Libervia though.
493 data[u'history'] = C.HISTORY_SKIP
485 return data 494 return data
486 495
487 def MessageReceivedTrigger(self, client, message_elt, post_treat): 496 def MessageReceivedTrigger(self, client, message_elt, post_treat):
488 if message_elt.getAttribute('type') == C.MESS_TYPE_GROUPCHAT: 497 if message_elt.getAttribute('type') == C.MESS_TYPE_GROUPCHAT:
489 # OTR is not possible in group chats 498 # OTR is not possible in group chats