changeset 1318:6c7d89843f1b frontends_multi_profiles

frontends (quick frontend): use of new getEntitiesData to get cached values for avatars on profile connection.
author Goffi <goffi@goffi.org>
date Mon, 09 Feb 2015 21:39:51 +0100
parents bd69d341d969
children 781ee3539252
files frontends/src/quick_frontend/constants.py frontends/src/quick_frontend/quick_app.py
diffstat 2 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/quick_frontend/constants.py	Mon Feb 09 21:39:51 2015 +0100
+++ b/frontends/src/quick_frontend/constants.py	Mon Feb 09 21:39:51 2015 +0100
@@ -30,3 +30,5 @@
     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'}
--- a/frontends/src/quick_frontend/quick_app.py	Mon Feb 09 21:39:51 2015 +0100
+++ b/frontends/src/quick_frontend/quick_app.py	Mon Feb 09 21:39:51 2015 +0100
@@ -33,6 +33,7 @@
     """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 @@
 
     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: