Mercurial > libervia-desktop-kivy
changeset 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 | ec11a35dcf14 |
children | 72290ebfaa8b |
files | cagou/core/common.py cagou/kv/common.kv cagou/plugins/plugin_wid_chat.kv cagou/plugins/plugin_wid_chat.py |
diffstat | 4 files changed, 29 insertions(+), 7 deletions(-) [+] |
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:
--- a/cagou/kv/common.kv Wed Apr 01 23:59:00 2020 +0200 +++ b/cagou/kv/common.kv Tue Apr 14 21:14:44 2020 +0200 @@ -46,7 +46,7 @@ Avatar: id: avatar pos_hint: {'x': 0, 'y': 0} - source: root.data.get('avatar') or app.default_avatar + source: root.data['avatar']['path'] if root.data.get('avatar') else app.default_avatar allow_stretch: True BoxLayout: id: label_box
--- a/cagou/plugins/plugin_wid_chat.kv Wed Apr 01 23:59:00 2020 +0200 +++ b/cagou/plugins/plugin_wid_chat.kv Tue Apr 14 21:14:44 2020 +0200 @@ -113,7 +113,7 @@ size_hint: None, 1 MessAvatar: id: avatar - source: (root.mess_data.avatar or '') if root.mess_data else '' + source: root.mess_data.avatar['path'] if root.mess_data and root.mess_data.avatar else app.default_avatar on_press: root.chat.addNick(root.nick) Widget: # use to push the avatar on the top
--- a/cagou/plugins/plugin_wid_chat.py Wed Apr 01 23:59:00 2020 +0200 +++ b/cagou/plugins/plugin_wid_chat.py Tue Apr 14 21:14:44 2020 +0200 @@ -320,7 +320,12 @@ def update(self, update_dict): if 'avatar' in update_dict: - self.avatar.source = update_dict['avatar'] + avatar_data = update_dict['avatar'] + if avatar_data is None: + source = G.host.getDefaultAvatar() + else: + source = avatar_data['path'] + self.avatar.source = source if 'status' in update_dict: status = update_dict['status'] self.delivery.text = '\u2714' if status == 'delivered' else ''