Mercurial > libervia-backend
diff src/plugins/plugin_xep_0045.py @ 350:abe08fcb42d7
plugin XEP-0045: added error callback to join's deferred, and a callback is created if join fail before calling MUCClient's join
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 31 May 2011 17:08:20 +0200 |
parents | 5bb1cfc105d0 |
children | f964dcec1611 |
line wrap: on
line diff
--- 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)