Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0045.py @ 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 | be3a301540c0 |
children | bf3f669a6052 |
comparison
equal
deleted
inserted
replaced
1355:33a21f06551d | 1356:c01cbd8fc8dd |
---|---|
63 def __init__(self, host): | 63 def __init__(self, host): |
64 log.info(_("Plugin XEP_0045 initialization")) | 64 log.info(_("Plugin XEP_0045 initialization")) |
65 self.host = host | 65 self.host = host |
66 self.clients = {} | 66 self.clients = {} |
67 self._sessions = memory.Sessions() | 67 self._sessions = memory.Sessions() |
68 host.bridge.addMethod("joinMUC", ".plugin", in_sign='ssa{ss}s', out_sign='s', method=self._join) | 68 host.bridge.addMethod("joinMUC", ".plugin", in_sign='ssa{ss}s', out_sign='s', method=self._join, async=True) |
69 host.bridge.addMethod("mucNick", ".plugin", in_sign='sss', out_sign='', method=self.mucNick) | 69 host.bridge.addMethod("mucNick", ".plugin", in_sign='sss', out_sign='', method=self.mucNick) |
70 host.bridge.addMethod("mucLeave", ".plugin", in_sign='ss', out_sign='', method=self.mucLeave, async=True) | 70 host.bridge.addMethod("mucLeave", ".plugin", in_sign='ss', out_sign='', method=self.mucLeave, async=True) |
71 host.bridge.addMethod("getRoomsJoined", ".plugin", in_sign='s', out_sign='a(sass)', method=self.getRoomsJoined) | 71 host.bridge.addMethod("getRoomsJoined", ".plugin", in_sign='s', out_sign='a(sass)', method=self.getRoomsJoined) |
72 host.bridge.addMethod("getRoomsSubjects", ".plugin", in_sign='s', out_sign='a(ss)', method=self.getRoomsSubjects) | 72 host.bridge.addMethod("getRoomsSubjects", ".plugin", in_sign='s', out_sign='a(ss)', method=self.getRoomsSubjects) |
73 host.bridge.addMethod("getUniqueRoomName", ".plugin", in_sign='ss', out_sign='s', method=self._getUniqueName) | 73 host.bridge.addMethod("getUniqueRoomName", ".plugin", in_sign='ss', out_sign='s', method=self._getUniqueName) |
308 return self.getUniqueName(muc_service or None, profile_key).full() | 308 return self.getUniqueName(muc_service or None, profile_key).full() |
309 | 309 |
310 def getUniqueName(self, muc_service=None, profile_key=C.PROF_KEY_NONE): | 310 def getUniqueName(self, muc_service=None, profile_key=C.PROF_KEY_NONE): |
311 """Return unique name for a room, avoiding collision | 311 """Return unique name for a room, avoiding collision |
312 | 312 |
313 @param muc_service: leave empty string to use the default service | 313 @param muc_service (jid.JID) : leave empty string to use the default service |
314 @return: unique room userhost, or '' if an error occured. | 314 @return: jid.JID (unique room bare JID) |
315 """ | 315 """ |
316 #TODO: we should use #RFC-0045 10.1.4 when available here | 316 #TODO: we should use #RFC-0045 10.1.4 when available here |
317 client = self.host.getClient(profile_key) | 317 client = self.host.getClient(profile_key) |
318 room_name = uuid.uuid1() | 318 room_name = uuid.uuid1() |
319 if muc_service is None: | 319 if muc_service is None: |
356 # > /usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py(480)_startRunCallbacks() | 356 # > /usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py(480)_startRunCallbacks() |
357 # -> raise AlreadyCalledError(extra) | 357 # -> raise AlreadyCalledError(extra) |
358 | 358 |
359 def _join(self, room_jid_s, nick, options={}, profile_key=C.PROF_KEY_NONE): | 359 def _join(self, room_jid_s, nick, options={}, profile_key=C.PROF_KEY_NONE): |
360 """join method used by bridge: use the join method, but doesn't return any deferred | 360 """join method used by bridge: use the join method, but doesn't return any deferred |
361 @return the room userhost (given value or unique generated name) | 361 @return: unicode (the room bare) |
362 """ | 362 """ |
363 profile = self.host.memory.getProfileName(profile_key) | 363 profile = self.host.memory.getProfileName(profile_key) |
364 if not self.checkClient(profile): | 364 if not self.checkClient(profile): |
365 return | 365 return |
366 if room_jid_s == "": | 366 if room_jid_s: |
367 room_jid_s = self.getUniqueName(profile_key=profile_key) | 367 try: |
368 try: | 368 room_jid = jid.JID(room_jid_s) |
369 room_jid = jid.JID(room_jid_s) | 369 except (RuntimeError, jid.InvalidFormat, AttributeError): |
370 except: | 370 mess = _("Invalid room JID: %s") % room_jid_s |
371 mess = _("Invalid room jid: %s") % room_jid_s | 371 log.warning(mess) |
372 log.warning(mess) | 372 self.host.bridge.newAlert(mess, _("Group chat error"), "ERROR", profile) |
373 self.host.bridge.newAlert(mess, _("Group chat error"), "ERROR", profile) | 373 return defer.succeed(None) |
374 return | 374 else: |
375 self.join(room_jid, nick, options, profile) | 375 room_jid = self.getUniqueName(profile_key=profile_key) |
376 # TODO: error management + signal in bridge | 376 # TODO: error management + signal in bridge |
377 return room_jid_s | 377 d = self.join(room_jid, nick, options, profile) |
378 return d.addCallback(lambda room: room.roomJID.userhost()) | |
378 | 379 |
379 def nick(self, room_jid, nick, profile_key): | 380 def nick(self, room_jid, nick, profile_key): |
380 profile = self.getProfileAssertInRoom(room_jid, profile_key) | 381 profile = self.getProfileAssertInRoom(room_jid, profile_key) |
381 return self.clients[profile].nick(room_jid, nick) | 382 return self.clients[profile].nick(room_jid, nick) |
382 | 383 |