diff sat/plugins/plugin_xep_0045.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 6acaa8244220
children 7b8d40b17451
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0045.py	Mon Jul 15 22:36:28 2019 +0200
+++ b/sat/plugins/plugin_xep_0045.py	Tue Jul 16 21:59:30 2019 +0200
@@ -496,6 +496,19 @@
                        errbackArgs=(client, room_jid, nick, password))
         return d
 
+    def popRooms(self, client):
+        """Remove rooms and return data needed to re-join them
+
+        This methods is to be called before a hot reconnection
+        @return (list[(jid.JID, unicode)]): arguments needed to re-join the rooms
+            This list can be used directly (unpacked) with self.join
+        """
+        args_list = []
+        for room in client._muc_client.joined_rooms.values():
+            client._muc_client._removeRoom(room.roomJID)
+            args_list.append((client, room.roomJID, room.nick))
+        return args_list
+
     def _nick(self, room_jid_s, nick, profile_key=C.PROF_KEY_NONE):
         client = self.host.getClient(profile_key)
         return self.nick(client, jid.JID(room_jid_s), nick)
@@ -785,7 +798,8 @@
             whois_msg.append(_("Show: %s") % user.show)
 
     def presenceTrigger(self, presence_elt, client):
-        # XXX: shouldn't it be done by the server ?!!
+        # FIXME: should we add a privacy parameters in settings to activate before
+        #        broadcasting the presence to all MUC rooms ?
         muc_client = client._muc_client
         for room_jid, room in muc_client.joined_rooms.iteritems():
             elt = xml_tools.elementCopy(presence_elt)