diff libervia.py @ 137:b145da69a218

server + browser side: new api fix
author Goffi <goffi@goffi.org>
date Mon, 22 Oct 2012 00:08:41 +0200
parents ceef355156de
children 008fa8d36602
line wrap: on
line diff
--- a/libervia.py	Thu Aug 02 01:10:04 2012 +0200
+++ b/libervia.py	Mon Oct 22 00:08:41 2012 +0200
@@ -84,7 +84,7 @@
         LiberviaJsonProxy.__init__(self, "/json_api",
                         ["getContacts", "addContact", "sendMessage", "sendMblog", "getLastMblogs", "getMassiveLastMblogs", "getProfileJid", "getHistory", "getPresenceStatus",
                          "joinMUC", "getRoomsJoined", "launchTarotGame", "getTarotCardsPaths", "tarotGameReady", "tarotGameContratChoosed",
-                         "tarotGamePlayCards", "launchRadioCollective", "getWaitingSub", "subscription", "delContact", "updateContact", "getCardCache"])
+                         "tarotGamePlayCards", "launchRadioCollective", "getWaitingSub", "subscription", "delContact", "updateContact", "getEntityData"])
 
 class BridgeSignals(LiberviaJsonProxy):
     def __init__(self, host):
@@ -141,12 +141,12 @@
 
     def getAvatar(self, jid_str):
         """Return avatar of a jid if in cache, else ask for it"""
-        def cacheCardResult(result):
+        def dataReceived(result):
             if result.has_key('avatar'):
-                self._updatedValueCb("card_avatar", {'jid':jid_str, 'avatar':result['avatar']})
+                self._entityDataUpdatedCb(jid_str, 'avatar', result['avatar'])
         
         if jid_str not in self.avatars_cache:
-            self.bridge.call('getCardCache', cacheCardResult, jid_str)
+            self.bridge.call('getEntityData', dataReceived, jid_str, ['avatar'])
             self.avatars_cache[jid_str] = "/media/misc/empty_avatar"
         return self.avatars_cache[jid_str]
 
@@ -265,8 +265,8 @@
             self._contactDeletedCb(*args)
         elif name == 'newContact':
             self._newContactCb(*args)
-        elif name == 'updatedValue':
-            self._updatedValueCb(*args)
+        elif name == 'entityDataUpdated':
+            self._entityDataUpdatedCb(*args)
 
     def _getProfileJidCB(self, jid):
         self.whoami = JID(jid)
@@ -423,21 +423,17 @@
     def _newContactCb(self, contact, attributes, groups):
         self.contact_panel.updateContact(contact, attributes, groups)
 
-    def _updatedValueCb(self, name, value):
-        if name == "card_avatar":
-            try:
-                jid = value['jid']
-                avatar = '/avatars/%s' % value['avatar']
-            except:
-                print ("ERROR: can't get avatar value")
-                return
+    def _entityDataUpdatedCb(self, entity_jid_s, key, value):
+        if key == "avatar":
+            entity_jid_s = value['entity_jid_s']
+            avatar = '/avatars/%s' % value
 
-            self.avatars_cache[jid] = avatar
+            self.avatars_cache[entity_jid_s] = avatar
 
             for lib_wid in self.libervia_widgets:
                 if isinstance(lib_wid, panels.MicroblogPanel):
-                    if lib_wid.isJidAccepted(jid) or (self.whoami and jid == self.whoami.bare):
-                        lib_wid.updateValue('avatar', jid, avatar)
+                    if lib_wid.isJidAccepted(entity_jid_s) or (self.whoami and entity_jid_s == self.whoami.bare):
+                        lib_wid.updateValue('avatar', entity_jid_s, avatar)