# HG changeset patch # User souliane # Date 1425742092 -3600 # Node ID c01cbd8fc8dd1fb06514e70308a6401b1df4ee7b # Parent 33a21f06551d4e1d5784057f5f70236d1917f555 plugin XEP-0045: make joinMUC asynchronous and fixes its handler diff -r 33a21f06551d -r c01cbd8fc8dd src/plugins/plugin_xep_0045.py --- a/src/plugins/plugin_xep_0045.py Fri Mar 06 16:06:38 2015 +0100 +++ b/src/plugins/plugin_xep_0045.py Sat Mar 07 16:28:12 2015 +0100 @@ -65,7 +65,7 @@ self.host = host self.clients = {} self._sessions = memory.Sessions() - host.bridge.addMethod("joinMUC", ".plugin", in_sign='ssa{ss}s', out_sign='s', method=self._join) + host.bridge.addMethod("joinMUC", ".plugin", in_sign='ssa{ss}s', out_sign='s', method=self._join, async=True) host.bridge.addMethod("mucNick", ".plugin", in_sign='sss', out_sign='', method=self.mucNick) host.bridge.addMethod("mucLeave", ".plugin", in_sign='ss', out_sign='', method=self.mucLeave, async=True) host.bridge.addMethod("getRoomsJoined", ".plugin", in_sign='s', out_sign='a(sass)', method=self.getRoomsJoined) @@ -310,8 +310,8 @@ def getUniqueName(self, muc_service=None, profile_key=C.PROF_KEY_NONE): """Return unique name for a room, avoiding collision - @param muc_service: leave empty string to use the default service - @return: unique room userhost, or '' if an error occured. + @param muc_service (jid.JID) : leave empty string to use the default service + @return: jid.JID (unique room bare JID) """ #TODO: we should use #RFC-0045 10.1.4 when available here client = self.host.getClient(profile_key) @@ -358,23 +358,24 @@ def _join(self, room_jid_s, nick, options={}, profile_key=C.PROF_KEY_NONE): """join method used by bridge: use the join method, but doesn't return any deferred - @return the room userhost (given value or unique generated name) + @return: unicode (the room bare) """ profile = self.host.memory.getProfileName(profile_key) if not self.checkClient(profile): return - if room_jid_s == "": - room_jid_s = self.getUniqueName(profile_key=profile_key) - try: - room_jid = jid.JID(room_jid_s) - except: - mess = _("Invalid room jid: %s") % room_jid_s - log.warning(mess) - self.host.bridge.newAlert(mess, _("Group chat error"), "ERROR", profile) - return - self.join(room_jid, nick, options, profile) + if room_jid_s: + try: + room_jid = jid.JID(room_jid_s) + except (RuntimeError, jid.InvalidFormat, AttributeError): + mess = _("Invalid room JID: %s") % room_jid_s + log.warning(mess) + self.host.bridge.newAlert(mess, _("Group chat error"), "ERROR", profile) + return defer.succeed(None) + else: + room_jid = self.getUniqueName(profile_key=profile_key) # TODO: error management + signal in bridge - return room_jid_s + d = self.join(room_jid, nick, options, profile) + return d.addCallback(lambda room: room.roomJID.userhost()) def nick(self, room_jid, nick, profile_key): profile = self.getProfileAssertInRoom(room_jid, profile_key)