Skip to content
Browse files

Fix looking up local and cached vcards.

  • Loading branch information...
1 parent 8a8926c commit d3e8993e22c46bccea37ab06b8fbc7abf97d959a @legastero legastero committed Apr 8, 2012
Showing with 18 additions and 6 deletions.
  1. +18 −6 sleekxmpp/plugins/xep_0054/vcard_temp.py
View
24 sleekxmpp/plugins/xep_0054/vcard_temp.py
@@ -55,27 +55,39 @@ def make_vcard(self):
def get_vcard(self, jid=None, ifrom=None, local=False, cached=False,
block=True, callback=None, timeout=None):
- if self.xmpp.is_component and jid.bare == self.xmpp.boundjid.bare:
+ if self.xmpp.is_component and jid.domain == self.xmpp.boundjid.domain:
local = True
- if local or cached:
+ if local:
vcard = self.api['get_vcard'](jid, None, ifrom)
if not isinstance(vcard, Iq):
iq = self.xmpp.Iq()
+ if vcard is None:
+ vcard = VCardTemp()
iq.append(vcard)
return iq
return vcard
+ if cached:
+ vcard = self.api['get_vcard'](jid, None, ifrom)
+ if vcard is not None:
+ if not isinstance(vcard, Iq):
+ iq = self.xmpp.Iq()
+ iq.append(vcard)
+ return iq
+ return vcard
+
iq = self.xmpp.Iq()
iq['to'] = jid
iq['from'] = ifrom
iq['type'] = 'get'
iq.enable('vcard_temp')
vcard = iq.send(block=block, callback=callback, timeout=timeout)
-
- self.api['set_vcard'](vcard['from'], args=vcard['vcard_temp'])
- return vcard
+
+ if block:
+ self.api['set_vcard'](vcard['from'], args=vcard['vcard_temp'])
+ return vcard
def publish_vcard(self, vcard=None, jid=None, block=True, ifrom=None,
callback=None, timeout=None):
@@ -111,7 +123,7 @@ def _set_vcard(self, jid, node, ifrom, vcard):
self._vcard_cache[jid.bare] = vcard
def _get_vcard(self, jid, node, ifrom, vcard):
- return self._vcard_cache.get(jid.bare, VCardTemp())
+ return self._vcard_cache.get(jid.bare, None)
def _del_vcard(self, jid, node, ifrom, vcard):
if jid.bare in self._vcard_cache:

0 comments on commit d3e8993

Please sign in to comment.
Something went wrong with that request. Please try again.