# HG changeset patch # User Goffi # Date 1306854500 -7200 # Node ID abe08fcb42d7b421d4c1fe1b3e637f5e5cc001d0 # Parent 3ec237e82aed8b0da0a53d72c79f53b5b040f526 plugin XEP-0045: added error callback to join's deferred, and a callback is created if join fail before calling MUCClient's join diff -r 3ec237e82aed -r abe08fcb42d7 src/plugins/plugin_xep_0045.py --- a/src/plugins/plugin_xep_0045.py Mon May 30 19:05:08 2011 +0200 +++ b/src/plugins/plugin_xep_0045.py Tue May 31 17:08:20 2011 +0200 @@ -139,27 +139,31 @@ return uuid.uuid1() def join(self, service, roomId, nick, profile_key='@DEFAULT@'): + def _errDeferred(exc_obj = Exception, txt='Error while joining room'): + d = defer.Deferred() + d.errback(exc_obj(txt)) + profile = self.host.memory.getProfileName(profile_key) if not self.__check_profile(profile): - return + return _errDeferred() room_jid = roomId+'@'+service if self.clients[profile].joined_rooms.has_key(room_jid): warning(_('%(profile)s is already in room %(room_jid)s') % {'profile':profile, 'room_jid':room_jid}) - return + return _errDeferred() info (_("[%(profile)s] is joining room %(room)s with nick %(nick)s") % {'profile':profile,'room':roomId+'@'+service, 'nick':nick}) try: return self.clients[profile].join(service, roomId, nick).addCallbacks(self.__room_joined, self.__err_joining_room, callbackKeywords={'profile':profile}, errbackKeywords={'profile':profile}) except: #XXX: this is a ugly workaround as MUCClient thrown an error if there is invalid chars in the room jid (like with the default string) #FIXME: must be removed when MUCClient manage this better - d = defer.Deferred() + d = _errDeferred(txt="ugly workaround") d.addErrback(self.__err_joining_room, profile) - d.errback(Exception("ugly workaround")) return d def _join(self, service, roomId, nick, profile_key='@DEFAULT@'): """join method used by bridge: use the _join method, but doesn't return any deferred""" - self.join(service, roomId, nick, profile_key) + d = self.join(service, roomId, nick, profile_key) + d.addErrback(lambda x: warning(_('Error while joining room'))) #TODO: error management + signal in bridge def getHandler(self, profile): self.clients[profile] = SatMUCClient(self)