plugin XEP-0045: added error callback to join's deferred, and a callback is created if join fail before calling MUCClient's join
This commit is contained in:
parent
3aaa30b727
commit
aeca822130
1 changed files with 9 additions and 5 deletions
|
|
@ -139,27 +139,31 @@ class XEP_0045():
|
|||
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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue