changeset 1356:c01cbd8fc8dd frontends_multi_profiles

plugin XEP-0045: make joinMUC asynchronous and fixes its handler
author souliane <souliane@mailoo.org>
date Sat, 07 Mar 2015 16:28:12 +0100
parents 33a21f06551d
children f296a54af386
files src/plugins/plugin_xep_0045.py
diffstat 1 files changed, 16 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- 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)