From 554ff650bff79488d259f32622dbc6b49842c243 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 7 Oct 2017 18:08:39 +0100 Subject: Display contact avatar in the roster. Implements XEP-0084 and XEP-0153. --- poezio/core/core.py | 5 +++++ poezio/core/handlers.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) (limited to 'poezio/core') 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 -- cgit v1.2.3