Mercurial > libervia-backend
diff 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 |
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0054.py Sun Aug 28 18:18:10 2016 +0200 +++ b/src/plugins/plugin_xep_0054.py Sun Aug 28 18:20:55 2016 +0200 @@ -252,30 +252,26 @@ defer.returnValue(dictionary) - def _VCardCb(self, answer, client): + def _getCardCb(self, iq_elt, to_jid, client): """Called after the first get IQ""" log.debug(_("VCard found")) - if answer.firstChildElement().name == "vCard": - try: - from_jid = jid.JID(answer["from"]) - except KeyError: - from_jid = client.jid.userhostJID() - d = self.vCard2Dict(client, answer.firstChildElement(), from_jid) - d.addCallback(lambda data: self.host.bridge.actionResult("RESULT", answer['id'], data, client.profile)) - else: - log.error(_("FIXME: vCard not found as first child element")) - self.host.bridge.actionResult("SUPPRESS", answer['id'], {}, client.profile) # FIXME: maybe an error message would be better + try: + vcard_elt = iq_elt.elements(NS_VCARD, "vCard").next() + except StopIteration: + log.warning(u"Can't find vCard element in answer for jid {jid}", jid=to_jid.full()) + return + try: + from_jid = jid.JID(iq_elt["from"]) + except KeyError: + from_jid = client.jid.userhostJID() + d = self.vCard2Dict(client, vcard_elt, from_jid) + return d - def _VCardEb(self, failure, client): + def _getCardEb(self, failure_, to_jid, client): """Called when something is wrong with registration""" - try: - self.host.bridge.actionResult("SUPPRESS", failure.value.stanza['id'], {}, client.profile) # FIXME: maybe an error message would be better - log.warning(_(u"Can't find VCard of %s") % failure.value.stanza['from']) - self.updateCache(client, jid.JID(failure.value.stanza['from']), "avatar", '') - except (AttributeError, KeyError): - # 'ConnectionLost' object has no attribute 'stanza' + sometimes 'from' key doesn't exist - log.warning(_(u"Can't find VCard: %s") % failure.getErrorMessage()) + log.warning(u"Can't get vCard for {jid}: {failure}".format(jid=to_jid.full, failure=failure_)) + self.updateCache(client, to_jid, "avatar", '') def _getCard(self, target_s, profile_key=C.PROF_KEY_NONE): client = self.host.getClient(profile_key) @@ -293,7 +289,7 @@ reg_request["from"] = client.jid.full() reg_request["to"] = to_jid.userhost() reg_request.addElement('vCard', NS_VCARD) - reg_request.send(to_jid.userhost()).addCallbacks(self._VCardCb, self._VCardEb, callbackArgs=[client], errbackArgs=[client]) + reg_request.send(to_jid.userhost()).addCallbacks(self._getCardCb, self._getCardEb, callbackArgs=[to_jid, client], errbackArgs=[to_jid, client]) return reg_request["id"] def getAvatarFile(self, avatar_hash):