From 91a04000d7dd3088bed33f80c3866ad525b33300 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 17 Jul 2021 11:31:36 +0200 Subject: [PATCH] Treat receiving chain length None as 0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It appears a receiving chain length set to None just means we haven't received any message for this session yet. It doesn't make sense to spam heartbeats at this stage Signed-off-by: Maxime “pep” Buquet --- slixmpp_omemo/__init__.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/slixmpp_omemo/__init__.py b/slixmpp_omemo/__init__.py index b885d8b..f35440d 100644 --- a/slixmpp_omemo/__init__.py +++ b/slixmpp_omemo/__init__.py @@ -536,8 +536,8 @@ class XEP_0384(BasePlugin): if session is None: continue skr = session._DoubleRatchet__skr - sending = skr.sending_chain_length or -1 - receiving = skr.receiving_chain_length or -1 + sending = skr.sending_chain_length or 0 + receiving = skr.receiving_chain_length or 0 lengths['sending'].append((did, sending)) lengths['receiving'].append((did, receiving)) @@ -556,8 +556,7 @@ class XEP_0384(BasePlugin): receiving_chain_lengths = self._chain_lengths(jid).get('receiving', []) lengths = map(lambda d_l: d_l[1], receiving_chain_lengths) - min_length = reduce(lambda x, d_l: min(x, d_l[1]), receiving_chain_lengths, 0) == -1 - return min_length == -1 or max(lengths, default=0) > self.heartbeat_after + return max(lengths, default=0) > self.heartbeat_after async def make_heartbeat(self, jid: JID) -> Message: """