From 5fe4e9164f4f4c8a2dec408ea136756fc191718a Mon Sep 17 00:00:00 2001 From: mathieui Date: Thu, 21 Jan 2021 21:02:56 +0100 Subject: [PATCH] Add a workaround for MUC reflections with an option for broken muc implementions which change message ids on the fly. --- README.rst | 1 - poezio_omemo/__init__.py | 22 ++++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 9af2968..b6b2034 100644 --- a/README.rst +++ b/README.rst @@ -53,6 +53,5 @@ information about autoloading plugins. TODO ---- -- MUC support. Needs support for handling MUC reflections in poezio first. - aesgcm - UI, various commands and indicators that messages are encrypted or not. diff --git a/poezio_omemo/__init__.py b/poezio_omemo/__init__.py index 53ea84a..c46a6d3 100644 --- a/poezio_omemo/__init__.py +++ b/poezio_omemo/__init__.py @@ -44,6 +44,8 @@ class Plugin(E2EEPlugin): (slixmpp_omemo.OMEMO_BASE_NS, 'encrypted'), ] + self_muc_messages: Dict[str, str] = {} + # TODO: Look into blind trust stuff. # https://gist.github.com/mar-v-in/b683220a55bc65dcdafc809be9c5d0e4 trust_states = { @@ -57,6 +59,12 @@ class Plugin(E2EEPlugin): } supported_tab_types = (DynamicConversationTab, StaticConversationTab, MucTab) + default_config = { + # Some MUC services may not reflect the message ids properly, in which + # case it is better to set this option to false. + 'enable_muc': True, + } + def init(self) -> None: super().init() @@ -102,7 +110,6 @@ class Plugin(E2EEPlugin): ] def decrypt(self, message: Message, jid: Optional[JID], tab: ChatTab) -> None: - if jid is None: self.display_error('Unable to decrypt the message.') return None @@ -120,9 +127,14 @@ class Plugin(E2EEPlugin): except (MissingOwnKey,): # The message is missing our own key, it was not encrypted for # us, and we can't decrypt it. - self.display_error( - 'I can\'t decrypt this message as it is not encrypted for me.' - ) + if (message['type'] == 'groupchat' and + message['id'] in self.self_muc_messages): + body = self.self_muc_messages.pop(message['id']) + else: + self.display_error( + 'I can\'t decrypt this message as it ' + 'is not encrypted for me.' + ) except (NoAvailableSession,) as exn: # We received a message from that contained a session that we # don't know about (deleted session storage, etc.). We can't @@ -152,6 +164,8 @@ class Plugin(E2EEPlugin): return None body = message['body'] + if self.config.get('enable_muc', True) and message['type'] == 'groupchat': + self.self_muc_messages[message['id']] = body expect_problems = {} # type: Dict[JID, List[int]] while True: