From b705b5688faeaaa005319939385252a0f88051f7 Mon Sep 17 00:00:00 2001 From: Goffi Date: Mon, 9 Feb 2015 21:39:51 +0100 Subject: [PATCH] frontends (quick frontend): use of new getEntitiesData to get cached values for avatars on profile connection. --- frontends/src/quick_frontend/constants.py | 2 ++ frontends/src/quick_frontend/quick_app.py | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/frontends/src/quick_frontend/constants.py b/frontends/src/quick_frontend/constants.py index 32f3d6f6..0cb1a26d 100644 --- a/frontends/src/quick_frontend/constants.py +++ b/frontends/src/quick_frontend/constants.py @@ -30,3 +30,5 @@ class Const(constants.Const): CONTACT_SPECIAL_GROUP = 'group' # group chat special entity CONTACT_SPECIAL_ALLOWED = (CONTACT_SPECIAL_GROUP,) # set of allowed values for special flag CONTACT_DATA_FORBIDDEN = {CONTACT_GROUPS, CONTACT_RESOURCES, CONTACT_MAIN_RESOURCE} # set of forbidden names for contact data + + LISTENERS = {'avatar'} diff --git a/frontends/src/quick_frontend/quick_app.py b/frontends/src/quick_frontend/quick_app.py index e8cf66f7..a41246bb 100644 --- a/frontends/src/quick_frontend/quick_app.py +++ b/frontends/src/quick_frontend/quick_app.py @@ -33,6 +33,7 @@ class ProfileManager(object): """Class managing all data relative to one profile, and plugging in mechanism""" host = None bridge = None + cache_keys_to_get = ['avatar'] def __init__(self, profile): self.profile = profile @@ -65,9 +66,21 @@ class ProfileManager(object): def _plug_profile_afterconnect(self): # Profile can be connected or not + # we get cached data + self.host.bridge.getEntitiesData([], ProfileManager.cache_keys_to_get, profile=self.profile, callback=self._plug_profile_gotCachedValues, errback=self._plug_profile_failedCachedValues) + + def _plug_profile_failedCachedValues(self, failure): + log.error("Couldn't get cached values: {}".format(failure)) + self._plug_profile_gotCachedValues({}) + + def _plug_profile_gotCachedValues(self, cached_values): # TODO: watched plugin contact_list = self.host.addContactList(self.profile) + for entity, data in cached_values.iteritems(): + for key, value in data.iteritems(): + self.host.contact_lists[self.profile].setCache(jid.JID(entity), key, value) + if not self.bridge.isConnected(self.profile): self.host.setStatusOnline(False, profile=self.profile) else: