From c936703941066e38b7aa08c848090407a6b16d8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Tue, 1 Mar 2022 22:47:12 +0100 Subject: [PATCH] Only call should_heartbeat if auto_heartbeat is enabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- slixmpp_omemo/__init__.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/slixmpp_omemo/__init__.py b/slixmpp_omemo/__init__.py index 24b5f20..0d21a35 100644 --- a/slixmpp_omemo/__init__.py +++ b/slixmpp_omemo/__init__.py @@ -720,14 +720,16 @@ class XEP_0384(BasePlugin): finally: asyncio.ensure_future(self._publish_bundle()) - should_heartbeat = await self._should_heartbeat(sender, isPrekeyMessage) - if self.auto_heartbeat and should_heartbeat: - log.debug('Decryption: Sending hearbeat to JID: %r', jid) - async def send_heartbeat(): - log.debug('Sending a heartbeat message') - msg = await self.make_heartbeat(JID(jid)) - msg.send() - asyncio.ensure_future(send_heartbeat()) + if self.auto_heartbeat: + log.debug('Checking if heartbeat is required. auto_hearbeat enabled.') + should_heartbeat = await self._should_heartbeat(sender, isPrekeyMessage) + if should_heartbeat: + log.debug('Decryption: Sending hearbeat to JID %r', jid, device) + async def send_heartbeat(): + log.debug('Sending a heartbeat message') + msg = await self.make_heartbeat(JID(jid)) + msg.send() + asyncio.ensure_future(send_heartbeat()) return body