plugin XEP-0045: make joinMUC asynchronous and fixes its handler

This commit is contained in:
souliane 2015-03-07 16:28:12 +01:00
commit 204f024e0c

View file

@ -65,7 +65,7 @@ class XEP_0045(object):
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 @@ class XEP_0045(object):
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 @@ class XEP_0045(object):
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)