diff cagou/core/common.py @ 458:1dd6db69406a

core: update avatar handling following backend changes: new avatar data format is handled. When ContactItem is created, avatar and nicknames are requested to backend if they are not already in cache.
author Goffi <goffi@goffi.org>
date Tue, 14 Apr 2020 21:14:44 +0200
parents efee0e0afb78
children 72290ebfaa8b
line wrap: on
line diff
--- a/cagou/core/common.py	Wed Apr 01 23:59:00 2020 +0200
+++ b/cagou/core/common.py	Tue Apr 14 21:14:44 2020 +0200
@@ -20,8 +20,6 @@
 
 import json
 from functools import partial, total_ordering
-from sat.core.i18n import _
-from sat.core import log as logging
 from kivy.uix.widget import Widget
 from kivy.uix.image import Image, AsyncImage
 from kivy.uix.label import Label
@@ -33,6 +31,9 @@
 from kivy.event import EventDispatcher
 from kivy.metrics import dp
 from kivy import properties
+from sat.core.i18n import _
+from sat.core import log as logging
+from sat.tools.common import data_format
 from sat_frontends.quick_frontend import quick_chat
 from .constants import Const as C
 from .common_widgets import CategorySeparator
@@ -59,8 +60,7 @@
     """An item from ContactList
 
     The item will drawn as an icon (JID avatar) with its jid below.
-    If "notifs" are present in data, a notification counter will be drawn above the
-    avatar.
+    If "badge_text" is set, a label with the text will be drawn above the avatar.
     """
     base_width = dp(150)
     avatar_layout = properties.ObjectProperty()
@@ -71,6 +71,23 @@
     data = properties.DictProperty()
     jid = properties.StringProperty('')
 
+    def on_kv_post(self, __):
+        if ((self.profile and self.jid and self.data is not None
+             and ('avatar' not in self.data or 'nicknames' not in self.data))):
+            G.host.bridge.identityGet(
+                self.jid, ['avatar', 'nicknames'], True, self.profile,
+                callback=self._identityGetCb,
+                errback=partial(
+                    G.host.errback,
+                    message=_("Can't retrieve identity for {jid}: {{msg}}").format(
+                        jid=self.jid)
+                )
+            )
+
+    def _identityGetCb(self, identity_raw):
+        identity_data = data_format.deserialise(identity_raw)
+        self.data.update(identity_data)
+
     def on_badge_text(self, wid, text):
         if text:
             if self.badge is not None: