# HG changeset patch
# User Goffi <goffi@goffi.org>
# Date 1580247730 -3600
# Node ID b9395c4df8b989213d8c49f46855d68b25c8d521
# Parent  48eafdab1c34342dbb077585c1576d3df30b79a3
core (xmpp): don't purge entity on disconnect if continueTrying is set

diff -r 48eafdab1c34 -r b9395c4df8b9 sat/core/xmpp.py
--- a/sat/core/xmpp.py	Tue Jan 28 22:27:42 2020 +0100
+++ b/sat/core/xmpp.py	Tue Jan 28 22:42:10 2020 +0100
@@ -374,15 +374,18 @@
             self.host_app.bridge.disconnected(
                 self.profile
             )  # we send the signal to the clients
-            self._connected_d.callback(None)
-            self.host_app.purgeEntity(
-                self.profile
-            )  # and we remove references to this client
             log.info(
                 _("********** [{profile}] DISCONNECTED **********").format(
                     profile=self.profile
                 )
             )
+            # we purge only if no new connection attempt is expected
+            if not self.factory.continueTrying:
+                log.debug("continueTrying not set, purging entity")
+                self._connected_d.callback(None)
+                # and we remove references to this client
+                self.host_app.purgeEntity(self.profile)
+
         if not self.conn_deferred.called:
             if reason is None:
                 err = error.StreamError("Server unexpectedly closed the connection")