Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
349:3ec237e82aed | 350:abe08fcb42d7 |
---|---|
137 #TODO: we should use #RFC-0045 10.1.4 when available here | 137 #TODO: we should use #RFC-0045 10.1.4 when available here |
138 #TODO: we should be able to select the MUC service here | 138 #TODO: we should be able to select the MUC service here |
139 return uuid.uuid1() | 139 return uuid.uuid1() |
140 | 140 |
141 def join(self, service, roomId, nick, profile_key='@DEFAULT@'): | 141 def join(self, service, roomId, nick, profile_key='@DEFAULT@'): |
142 def _errDeferred(exc_obj = Exception, txt='Error while joining room'): | |
143 d = defer.Deferred() | |
144 d.errback(exc_obj(txt)) | |
145 | |
142 profile = self.host.memory.getProfileName(profile_key) | 146 profile = self.host.memory.getProfileName(profile_key) |
143 if not self.__check_profile(profile): | 147 if not self.__check_profile(profile): |
144 return | 148 return _errDeferred() |
145 room_jid = roomId+'@'+service | 149 room_jid = roomId+'@'+service |
146 if self.clients[profile].joined_rooms.has_key(room_jid): | 150 if self.clients[profile].joined_rooms.has_key(room_jid): |
147 warning(_('%(profile)s is already in room %(room_jid)s') % {'profile':profile, 'room_jid':room_jid}) | 151 warning(_('%(profile)s is already in room %(room_jid)s') % {'profile':profile, 'room_jid':room_jid}) |
148 return | 152 return _errDeferred() |
149 info (_("[%(profile)s] is joining room %(room)s with nick %(nick)s") % {'profile':profile,'room':roomId+'@'+service, 'nick':nick}) | 153 info (_("[%(profile)s] is joining room %(room)s with nick %(nick)s") % {'profile':profile,'room':roomId+'@'+service, 'nick':nick}) |
150 try: | 154 try: |
151 return self.clients[profile].join(service, roomId, nick).addCallbacks(self.__room_joined, self.__err_joining_room, callbackKeywords={'profile':profile}, errbackKeywords={'profile':profile}) | 155 return self.clients[profile].join(service, roomId, nick).addCallbacks(self.__room_joined, self.__err_joining_room, callbackKeywords={'profile':profile}, errbackKeywords={'profile':profile}) |
152 except: | 156 except: |
153 #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) | 157 #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) |
154 #FIXME: must be removed when MUCClient manage this better | 158 #FIXME: must be removed when MUCClient manage this better |
155 d = defer.Deferred() | 159 d = _errDeferred(txt="ugly workaround") |
156 d.addErrback(self.__err_joining_room, profile) | 160 d.addErrback(self.__err_joining_room, profile) |
157 d.errback(Exception("ugly workaround")) | |
158 return d | 161 return d |
159 | 162 |
160 def _join(self, service, roomId, nick, profile_key='@DEFAULT@'): | 163 def _join(self, service, roomId, nick, profile_key='@DEFAULT@'): |
161 """join method used by bridge: use the _join method, but doesn't return any deferred""" | 164 """join method used by bridge: use the _join method, but doesn't return any deferred""" |
162 self.join(service, roomId, nick, profile_key) | 165 d = self.join(service, roomId, nick, profile_key) |
166 d.addErrback(lambda x: warning(_('Error while joining room'))) #TODO: error management + signal in bridge | |
163 | 167 |
164 def getHandler(self, profile): | 168 def getHandler(self, profile): |
165 self.clients[profile] = SatMUCClient(self) | 169 self.clients[profile] = SatMUCClient(self) |
166 return self.clients[profile] | 170 return self.clients[profile] |
167 | 171 |