Treat receiving chain length None as 0

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 <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2021-07-17 11:31:36 +02:00
parent baf29cb05f
commit 91a04000d7
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

@ -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:
"""