From e00c646d95689b27e63bc886510775efbcb9bf86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Wed, 15 Dec 2021 00:56:19 +0100 Subject: [PATCH] echo_client: Handle decrypt_message's Optional-ness MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also comment about it Signed-off-by: Maxime “pep” Buquet --- examples/echo_client.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/echo_client.py b/examples/echo_client.py index a4ae84e..8239b06 100644 --- a/examples/echo_client.py +++ b/examples/echo_client.py @@ -150,6 +150,11 @@ class EchoBot(ClientXMPP): try: encrypted = msg['omemo_encrypted'] body = self['xep_0384'].decrypt_message(encrypted, mfrom, allow_untrusted) + # decrypt_message returns Optional[str]. It is possible to get + # body-less OMEMO message (see KeyTransportMessages), currently + # used for example to send heartbeats to other devices. + if body is None: + return None decoded = body.decode('utf8') if self.is_command(decoded): await self.handle_command(mto, mtype, decoded)