plugin XEP-0045: make joinMUC asynchronous and fixes its handler
This commit is contained in:
parent
b524d41446
commit
204f024e0c
1 changed files with 16 additions and 15 deletions
|
|
@ -65,7 +65,7 @@ class XEP_0045(object):
|
||||||
self.host = host
|
self.host = host
|
||||||
self.clients = {}
|
self.clients = {}
|
||||||
self._sessions = memory.Sessions()
|
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("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("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)
|
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):
|
def getUniqueName(self, muc_service=None, profile_key=C.PROF_KEY_NONE):
|
||||||
"""Return unique name for a room, avoiding collision
|
"""Return unique name for a room, avoiding collision
|
||||||
|
|
||||||
@param muc_service: leave empty string to use the default service
|
@param muc_service (jid.JID) : leave empty string to use the default service
|
||||||
@return: unique room userhost, or '' if an error occured.
|
@return: jid.JID (unique room bare JID)
|
||||||
"""
|
"""
|
||||||
#TODO: we should use #RFC-0045 10.1.4 when available here
|
#TODO: we should use #RFC-0045 10.1.4 when available here
|
||||||
client = self.host.getClient(profile_key)
|
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):
|
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
|
"""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)
|
profile = self.host.memory.getProfileName(profile_key)
|
||||||
if not self.checkClient(profile):
|
if not self.checkClient(profile):
|
||||||
return
|
return
|
||||||
if room_jid_s == "":
|
if room_jid_s:
|
||||||
room_jid_s = self.getUniqueName(profile_key=profile_key)
|
try:
|
||||||
try:
|
room_jid = jid.JID(room_jid_s)
|
||||||
room_jid = jid.JID(room_jid_s)
|
except (RuntimeError, jid.InvalidFormat, AttributeError):
|
||||||
except:
|
mess = _("Invalid room JID: %s") % room_jid_s
|
||||||
mess = _("Invalid room jid: %s") % room_jid_s
|
log.warning(mess)
|
||||||
log.warning(mess)
|
self.host.bridge.newAlert(mess, _("Group chat error"), "ERROR", profile)
|
||||||
self.host.bridge.newAlert(mess, _("Group chat error"), "ERROR", profile)
|
return defer.succeed(None)
|
||||||
return
|
else:
|
||||||
self.join(room_jid, nick, options, profile)
|
room_jid = self.getUniqueName(profile_key=profile_key)
|
||||||
# TODO: error management + signal in bridge
|
# 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):
|
def nick(self, room_jid, nick, profile_key):
|
||||||
profile = self.getProfileAssertInRoom(room_jid, profile_key)
|
profile = self.getProfileAssertInRoom(room_jid, profile_key)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue