diff src/browser/libervia_main.py @ 606:7af8f4ab3675 frontends_multi_profiles

browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
author Goffi <goffi@goffi.org>
date Mon, 09 Feb 2015 21:55:16 +0100
parents be2891462e63
children ec77c2bc18d3
line wrap: on
line diff
--- a/src/browser/libervia_main.py	Mon Feb 09 21:46:15 2015 +0100
+++ b/src/browser/libervia_main.py	Mon Feb 09 21:55:16 2015 +0100
@@ -51,6 +51,7 @@
 from sat_browser import notification
 
 from sat_browser.constants import Const as C
+import os.path
 
 
 try:
@@ -98,7 +99,6 @@
         self.cached_params = {}
 
         #FIXME: to be removed (managed with cache and in quick_frontend
-        self.avatars_cache = {}  # keep track of jid's avatar hash (key=jid, value=file)
         #FIXME: microblog cache should be managed directly in blog module
         self.mblog_cache = []  # used to keep our own blog entries in memory, to show them in new mblog panel
 
@@ -197,26 +197,21 @@
 
     # FIXME: must not call _entityDataUpdatedCb by itself
     #        should not get VCard, backend plugin must be fixed too
-    # def getAvatar(self, jid_str):
-    #     """Return avatar of a jid if in cache, else ask for it.
+    def getAvatarURL(self, jid_):
+        """Return avatar of a jid if in cache, else ask for it.
 
-    #     @param jid_str (str): JID of the contact
-    #     @return: the URL to the avatar (str)
-    #     """
-    #     def dataReceived(result):
-    #         if 'avatar' in result:
-    #             self._entityDataUpdatedCb(jid_str, 'avatar', result['avatar'])
-    #         else:
-    #             self.bridge.call("getCard", None, jid_str)
-
-    #     def avatarError(error_data):
-    #         # The jid is maybe not in our roster, we ask for the VCard
-    #         self.bridge.call("getCard", None, jid_str)
-
-    #     if jid_str not in self.avatars_cache:
-    #         self.bridge.call('getEntityData', (dataReceived, avatarError), jid_str, ['avatar'])
-    #         self.avatars_cache[jid_str] = C.DEFAULT_AVATAR
-    #     return self.avatars_cache[jid_str]
+        @param jid_ (jid.JID): JID of the contact
+        @return: the URL to the avatar (str)
+        """
+        assert isinstance(jid_, jid.JID)
+        avatar_hash = self.contact_lists[C.PROF_KEY_NONE].getCache(jid_, 'avatar')
+        if avatar_hash is None:
+            # we have no value for avatar_hash, so we request the vcard
+            self.bridge.getCard(unicode(jid_), profile=C.PROF_KEY_NONE)
+        if not avatar_hash:
+            return C.DEFAULT_AVATAR_URL
+        ret = os.path.join(C.AVATARS_DIR, avatar_hash)
+        return ret
 
     def registerWidget(self, wid):
         log.debug("Registering %s" % wid.getDebugName())
@@ -348,8 +343,8 @@
         # for cat, name in C.CACHED_PARAMS:
         #     self.bridge.call('asyncGetParamA', param_cb(cat, name, count), name, cat)
 
-    def profilePlugged(self, profile):
-        #we fill the panels already here
+    def profilePlugged(self, dummy):
+        # we fill the panels already here
         for widget in self.widgets.getWidgets(blog.MicroblogPanel):
             if widget.accept_all():
                 self.bridge.getMassiveLastMblogs('ALL', [], 10, profile=C.PROF_KEY_NONE, callback=widget.massiveInsert)
@@ -424,7 +419,7 @@
         """
         if data is None:
             data = {}
-        self.bridge.call('launchAction', (self._actionCb, self._actionEb), callback_id, data)
+        self.bridge.launchAction(callback_id, data, profile=C.PROF_KEY_NONE, callback=self._actionCb, errback=self._actionEb)
 
     def _getContactsCB(self, contacts_data):
         for contact_ in contacts_data:
@@ -800,6 +795,7 @@
         self.contact_panel.updateContact(contact_jid, attributes, groups)
 
     def _entityDataUpdatedCb(self, entity_jid_s, key, value):
+        raise Exception # FIXME should not be here
         if key == "avatar":
             avatar = '/' + C.AVATARS_DIR + value
             self.avatars_cache[entity_jid_s] = avatar