echo_client: Handle decrypt_message's Optional-ness

Also comment about it

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2021-12-15 00:56:19 +01:00
parent 05b5705f22
commit e00c646d95
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

@ -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)