comparison 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
comparison
equal deleted inserted replaced
3007:420897488080 3008:c8c68a3b0a79
494 d.addCallbacks(self._joinCb, self._joinEb, 494 d.addCallbacks(self._joinCb, self._joinEb,
495 (client, room_jid, nick), 495 (client, room_jid, nick),
496 errbackArgs=(client, room_jid, nick, password)) 496 errbackArgs=(client, room_jid, nick, password))
497 return d 497 return d
498 498
499 def popRooms(self, client):
500 """Remove rooms and return data needed to re-join them
501
502 This methods is to be called before a hot reconnection
503 @return (list[(jid.JID, unicode)]): arguments needed to re-join the rooms
504 This list can be used directly (unpacked) with self.join
505 """
506 args_list = []
507 for room in client._muc_client.joined_rooms.values():
508 client._muc_client._removeRoom(room.roomJID)
509 args_list.append((client, room.roomJID, room.nick))
510 return args_list
511
499 def _nick(self, room_jid_s, nick, profile_key=C.PROF_KEY_NONE): 512 def _nick(self, room_jid_s, nick, profile_key=C.PROF_KEY_NONE):
500 client = self.host.getClient(profile_key) 513 client = self.host.getClient(profile_key)
501 return self.nick(client, jid.JID(room_jid_s), nick) 514 return self.nick(client, jid.JID(room_jid_s), nick)
502 515
503 def nick(self, client, room_jid, nick): 516 def nick(self, client, room_jid, nick):
783 whois_msg.append(_("Status: %s") % user.status) 796 whois_msg.append(_("Status: %s") % user.status)
784 if user.show: 797 if user.show:
785 whois_msg.append(_("Show: %s") % user.show) 798 whois_msg.append(_("Show: %s") % user.show)
786 799
787 def presenceTrigger(self, presence_elt, client): 800 def presenceTrigger(self, presence_elt, client):
788 # XXX: shouldn't it be done by the server ?!! 801 # FIXME: should we add a privacy parameters in settings to activate before
802 # broadcasting the presence to all MUC rooms ?
789 muc_client = client._muc_client 803 muc_client = client._muc_client
790 for room_jid, room in muc_client.joined_rooms.iteritems(): 804 for room_jid, room in muc_client.joined_rooms.iteritems():
791 elt = xml_tools.elementCopy(presence_elt) 805 elt = xml_tools.elementCopy(presence_elt)
792 elt['to'] = room_jid.userhost() + '/' + room.nick 806 elt['to'] = room_jid.userhost() + '/' + room.nick
793 client.presence.send(elt) 807 client.presence.send(elt)