summaryrefslogtreecommitdiff
path: root/poezio/core
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2017-10-07 18:08:39 +0100
committerEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2017-10-07 18:11:33 +0100
commit554ff650bff79488d259f32622dbc6b49842c243 (patch)
tree0ca47c1266b91829e74198de8be15fc0407270ab /poezio/core
parent232ef11630eed44d9f15b2e09b35bffb022c7afd (diff)
downloadpoezio-554ff650bff79488d259f32622dbc6b49842c243.tar.gz
poezio-554ff650bff79488d259f32622dbc6b49842c243.tar.bz2
poezio-554ff650bff79488d259f32622dbc6b49842c243.tar.xz
poezio-554ff650bff79488d259f32622dbc6b49842c243.zip
Display contact avatar in the roster.
Implements XEP-0084 and XEP-0153.
Diffstat (limited to 'poezio/core')
-rw-r--r--poezio/core/core.py5
-rw-r--r--poezio/core/handlers.py37
2 files changed, 42 insertions, 0 deletions
diff --git a/poezio/core/core.py b/poezio/core/core.py
index 410ac83b..7d4e46e5 100644
--- a/poezio/core/core.py
+++ b/poezio/core/core.py
@@ -261,6 +261,11 @@ class Core(object):
connection.MatchAll(None),
self.handler.incoming_stanza)
self.xmpp.register_handler(all_stanzas)
+ if config.get('enable_avatars'):
+ self.xmpp.add_event_handler("vcard_avatar_update",
+ self.handler.on_vcard_avatar)
+ self.xmpp.add_event_handler("avatar_metadata_publish",
+ self.handler.on_0084_avatar)
if config.get('enable_user_tune'):
self.xmpp.add_event_handler("user_tune_publish",
self.handler.on_tune_event)
diff --git a/poezio/core/handlers.py b/poezio/core/handlers.py
index a3d447bd..d8983041 100644
--- a/poezio/core/handlers.py
+++ b/poezio/core/handlers.py
@@ -355,6 +355,43 @@ class HandlerCore:
else:
self.core.refresh_window()
+ @asyncio.coroutine
+ def on_0084_avatar(self, msg):
+ jid = msg['from'].bare
+ contact = roster[jid]
+ if not contact:
+ return
+ log.debug('Received 0084 avatar update from %s', jid)
+ try:
+ metadata = msg['pubsub_event']['items']['item']['avatar_metadata']['items']
+ except Exception:
+ return
+ for info in metadata:
+ if not info['url']:
+ try:
+ result = yield from self.core.xmpp['xep_0084'].retrieve_avatar(jid,
+ info['id'],
+ timeout=10)
+ contact.avatar = result['pubsub']['items']['item']['avatar_data']['value']
+ except Exception:
+ log.exception('Failed retrieving 0084 data from %s:', jid)
+ return
+ log.debug('Received %s avatar: %s', jid, info['type'])
+
+ @asyncio.coroutine
+ def on_vcard_avatar(self, pres):
+ jid = pres['from'].bare
+ log.debug('Received vCard avatar update from %s', jid)
+ try:
+ result = yield from self.core.xmpp['xep_0054'].get_vcard(jid,
+ cached=True,
+ timeout=10)
+ contact.avatar = result['vcard_temp']['PHOTO']
+ except Exception:
+ log.exception('Failed retrieving vCard from %s:', jid)
+ return
+ log.debug('Received %s avatar: %s', jid, avatar['TYPE'])
+
def on_nick_received(self, message):
"""
Called when a pep notification for an user nickname