diff sat/plugins/plugin_xep_0198.py @ 3008:c8c68a3b0a79

plugins XEP-0045, XEP-0198: rejoin MUC rooms while a hot reconnection is done: when resuming is not possible with stream management, a hot reconnection is done (reconnecting without restarting every plugin). This was causing trouble for joined MUC rooms, which were not accessible anymore (because they were not re-joined). This patch fixes it by clearing rooms first (to avoid considering the room joined and broadcasting the initial presence to them), then re-joining them. fix 322
author Goffi <goffi@goffi.org>
date Tue, 16 Jul 2019 21:59:30 +0200
parents 9213c6dff48d
children 93da7c6f8e0c
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0198.py	Mon Jul 15 22:36:28 2019 +0200
+++ b/sat/plugins/plugin_xep_0198.py	Tue Jul 16 21:59:30 2019 +0200
@@ -35,14 +35,15 @@
 log = getLogger(__name__)
 
 PLUGIN_INFO = {
-    C.PI_NAME: "Stream Management",
-    C.PI_IMPORT_NAME: "XEP-0198",
-    C.PI_TYPE: "XEP",
+    C.PI_NAME: u"Stream Management",
+    C.PI_IMPORT_NAME: u"XEP-0198",
+    C.PI_TYPE: u"XEP",
     C.PI_MODES: C.PLUG_MODE_BOTH,
-    C.PI_PROTOCOLS: ["XEP-0198"],
+    C.PI_PROTOCOLS: [u"XEP-0198"],
     C.PI_DEPENDENCIES: [],
-    C.PI_MAIN: "XEP_0198",
-    C.PI_HANDLER: "yes",
+    C.PI_RECOMMENDATIONS: [u"XEP-0045"],
+    C.PI_MAIN: u"XEP_0198",
+    C.PI_HANDLER: u"yes",
     C.PI_DESCRIPTION: _(u"""Implementation of Stream Management"""),
 }
 
@@ -394,6 +395,10 @@
                 client.conn_deferred = defer.Deferred()
             else:
                 log.error(u"conn_deferred should be called at this point")
+            plg_0045 = self.host.plugins.get(u'XEP-0045')
+            if plg_0045 is not None:
+                # we have to remove joined rooms
+                muc_join_args = plg_0045.popRooms(client)
             # we need to recreate roster
             client.handlers.remove(client.roster)
             client.roster = client.roster.__class__(self.host)
@@ -412,6 +417,10 @@
             d.addCallback(lambda __: client.roster.got_roster)
             # initial presence must be sent manually
             d.addCallback(lambda __: client.presence.available())
+            if plg_0045 is not None:
+                muc_d_list = defer.DeferredList(
+                    [plg_0045.join(*args) for args in muc_join_args])
+                d.addCallback(lambda __: muc_d_list)
 
     def onReceive(self, element, client):
         if not client.is_component:
@@ -437,7 +446,7 @@
         session.ack_requested = False
         if self._ack_timeout:
             if session.req_timer is None:
-                log.error("reg_timer should be set")
+                log.error("req_timer should be set")
             else:
                 session.req_timer.cancel()
                 session.req_timer = None