comparison src/plugins/plugin_xep_0054.py @ 2046:b99bd02ea643

plugin XEP-0045, XEP-0054, XEP-0096: deprecated bridge method are not used anymore
author Goffi <goffi@goffi.org>
date Sun, 28 Aug 2016 18:20:55 +0200
parents 8156f2116dc9
children d44360763262
comparison
equal deleted inserted replaced
2045:48536a22b599 2046:b99bd02ea643
250 log.debug(u"reseting vcard datum [{datum}] for {entity}".format(datum=datum, entity=target.full())) 250 log.debug(u"reseting vcard datum [{datum}] for {entity}".format(datum=datum, entity=target.full()))
251 self.updateCache(client, target, datum, '') 251 self.updateCache(client, target, datum, '')
252 252
253 defer.returnValue(dictionary) 253 defer.returnValue(dictionary)
254 254
255 def _VCardCb(self, answer, client): 255 def _getCardCb(self, iq_elt, to_jid, client):
256 """Called after the first get IQ""" 256 """Called after the first get IQ"""
257 log.debug(_("VCard found")) 257 log.debug(_("VCard found"))
258 258
259 if answer.firstChildElement().name == "vCard": 259 try:
260 try: 260 vcard_elt = iq_elt.elements(NS_VCARD, "vCard").next()
261 from_jid = jid.JID(answer["from"]) 261 except StopIteration:
262 except KeyError: 262 log.warning(u"Can't find vCard element in answer for jid {jid}", jid=to_jid.full())
263 from_jid = client.jid.userhostJID() 263 return
264 d = self.vCard2Dict(client, answer.firstChildElement(), from_jid) 264 try:
265 d.addCallback(lambda data: self.host.bridge.actionResult("RESULT", answer['id'], data, client.profile)) 265 from_jid = jid.JID(iq_elt["from"])
266 else: 266 except KeyError:
267 log.error(_("FIXME: vCard not found as first child element")) 267 from_jid = client.jid.userhostJID()
268 self.host.bridge.actionResult("SUPPRESS", answer['id'], {}, client.profile) # FIXME: maybe an error message would be better 268 d = self.vCard2Dict(client, vcard_elt, from_jid)
269 269 return d
270 def _VCardEb(self, failure, client): 270
271 def _getCardEb(self, failure_, to_jid, client):
271 """Called when something is wrong with registration""" 272 """Called when something is wrong with registration"""
272 try: 273 log.warning(u"Can't get vCard for {jid}: {failure}".format(jid=to_jid.full, failure=failure_))
273 self.host.bridge.actionResult("SUPPRESS", failure.value.stanza['id'], {}, client.profile) # FIXME: maybe an error message would be better 274 self.updateCache(client, to_jid, "avatar", '')
274 log.warning(_(u"Can't find VCard of %s") % failure.value.stanza['from'])
275 self.updateCache(client, jid.JID(failure.value.stanza['from']), "avatar", '')
276 except (AttributeError, KeyError):
277 # 'ConnectionLost' object has no attribute 'stanza' + sometimes 'from' key doesn't exist
278 log.warning(_(u"Can't find VCard: %s") % failure.getErrorMessage())
279 275
280 def _getCard(self, target_s, profile_key=C.PROF_KEY_NONE): 276 def _getCard(self, target_s, profile_key=C.PROF_KEY_NONE):
281 client = self.host.getClient(profile_key) 277 client = self.host.getClient(profile_key)
282 return self.getCard(client, jid.JID(target_s)) 278 return self.getCard(client, jid.JID(target_s))
283 279
291 log.debug(_(u"Asking for %s's VCard") % to_jid.userhost()) 287 log.debug(_(u"Asking for %s's VCard") % to_jid.userhost())
292 reg_request = client.IQ('get') 288 reg_request = client.IQ('get')
293 reg_request["from"] = client.jid.full() 289 reg_request["from"] = client.jid.full()
294 reg_request["to"] = to_jid.userhost() 290 reg_request["to"] = to_jid.userhost()
295 reg_request.addElement('vCard', NS_VCARD) 291 reg_request.addElement('vCard', NS_VCARD)
296 reg_request.send(to_jid.userhost()).addCallbacks(self._VCardCb, self._VCardEb, callbackArgs=[client], errbackArgs=[client]) 292 reg_request.send(to_jid.userhost()).addCallbacks(self._getCardCb, self._getCardEb, callbackArgs=[to_jid, client], errbackArgs=[to_jid, client])
297 return reg_request["id"] 293 return reg_request["id"]
298 294
299 def getAvatarFile(self, avatar_hash): 295 def getAvatarFile(self, avatar_hash):
300 """Give the full path of avatar from hash 296 """Give the full path of avatar from hash
301 @param hash: SHA1 hash 297 @param hash: SHA1 hash