changeset 1683:9bf1262297f2

plugin XEP-0054: fixed presence issue when avatar is not in cache
author Goffi <goffi@goffi.org>
date Wed, 25 Nov 2015 20:08:33 +0100
parents 61391d863709
children 373ce871b0f3
files src/plugins/plugin_xep_0054.py
diffstat 1 files changed, 6 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0054.py	Wed Nov 25 20:01:39 2015 +0100
+++ b/src/plugins/plugin_xep_0054.py	Wed Nov 25 20:08:33 2015 +0100
@@ -97,8 +97,13 @@
 
     def presenceAvailableTrigger(self, presence_elt, client):
         if client.jid.userhost() in self.cache[client.profile]:
+            try:
+                avatar_hash = self.cache[client.profile][client.jid.userhost()]['avatar']
+            except KeyError:
+                log.info(u"No avatar in cache for {}".format(client.jid.userhost()))
+                return True
             x_elt = domish.Element((NS_VCARD_UPDATE, 'x'))
-            x_elt.addElement('photo', content=self.cache[client.profile][client.jid.userhost()]['avatar'])
+            x_elt.addElement('photo', content=avatar_hash)
             presence_elt.addChild(x_elt)
 
         return True