From d1a3a35df6f5c866276469c204ca7b8d933f06cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Fri, 7 Jun 2019 17:23:06 +0200 Subject: e2ee api: Utilize priority in event handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- poezio/plugin_e2ee.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'poezio/plugin_e2ee.py') diff --git a/poezio/plugin_e2ee.py b/poezio/plugin_e2ee.py index e4497113..86b871fd 100644 --- a/poezio/plugin_e2ee.py +++ b/poezio/plugin_e2ee.py @@ -56,12 +56,17 @@ class E2EEPlugin(BasePlugin): if self.encryption_short_name is None: self.encryption_short_name = self.encryption_name - self.api.add_event_handler('muc_msg', self._decrypt) - self.api.add_event_handler('muc_say', self._encrypt) - self.api.add_event_handler('conversation_msg', self._decrypt) - self.api.add_event_handler('conversation_say', self._encrypt) - self.api.add_event_handler('private_msg', self._decrypt) - self.api.add_event_handler('private_say', self._encrypt) + # Ensure decryption is done before everything, so that other handlers + # don't have to know about the encryption mechanism. + self.api.add_event_handler('muc_msg', self._decrypt, priority=0) + self.api.add_event_handler('conversation_msg', self._decrypt, priority=0) + self.api.add_event_handler('private_msg', self._decrypt, priority=0) + + # Ensure encryption is done after everything, so that whatever can be + # encrypted is encrypted, and no plain element slips in. + self.api.add_event_handler('muc_say', self._encrypt, priority=100) + self.api.add_event_handler('conversation_say', self._encrypt, priority=100) + self.api.add_event_handler('private_say', self._encrypt, priority=100) for tab_t in (DynamicConversationTab, PrivateTab, MucTab): self.api.add_tab_command( -- cgit v1.2.3