changeset 137:b145da69a218

server + browser side: new api fix
author Goffi <goffi@goffi.org>
date Mon, 22 Oct 2012 00:08:41 +0200
parents 9d7d98954e34
children 008fa8d36602
files browser_side/panels.py libervia.py libervia.tac
diffstat 3 files changed, 23 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/browser_side/panels.py	Thu Aug 02 01:10:04 2012 +0200
+++ b/browser_side/panels.py	Mon Oct 22 00:08:41 2012 +0200
@@ -735,7 +735,7 @@
         """Print the initial history"""
         def getHistoryCB(history):
             for line in history:
-                timestamp, from_jid, to_jid, message = line
+                timestamp, from_jid, to_jid, message, mess_type = line
                 self.printMessage(from_jid, message, timestamp)
         self.host.bridge.call('getHistory', getHistoryCB, self.host.whoami.bare, self.target.bare, size, True)
    
--- 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)
                         
 
 
--- a/libervia.tac	Thu Aug 02 01:10:04 2012 +0200
+++ b/libervia.tac	Mon Oct 22 00:08:41 2012 +0200
@@ -252,8 +252,8 @@
             for line in result_dbus:
                 #XXX: we have to do this stupid thing because Python D-Bus use its own types instead of standard types
                 #     and txJsonRPC doesn't accept D-Bus types, resulting in a empty query
-                timestamp, from_jid, to_jid, message = line
-                result.append((float(timestamp), unicode(from_jid), unicode(to_jid), unicode(message)))
+                timestamp, from_jid, to_jid, message, mess_type = line
+                result.append((float(timestamp), unicode(from_jid), unicode(to_jid), unicode(message), unicode(mess_type)))
             return result
         d.addCallback(show)
         return d
@@ -304,12 +304,13 @@
         profile = ISATSession(self.session).profile
         self.sat_host.bridge.radiocolLaunch(invited, profile)
 
-    def jsonrpc_getCardCache(self, jid):
-        """Get the avatar of a contact
-        @param jid: jid of contact from who we want the avatar
-        @return: path to the avatar image"""
+    def jsonrpc_getEntityData(self, jid, keys):
+        """Get cached data for an entit
+        @param jid: jid of contact from who we want data
+        @param keys: name of data we want (list)
+        @return: requested data"""
         profile = ISATSession(self.session).profile
-        return self.sat_host.bridge.getCardCache(jid, profile)
+        return self.sat_host.bridge.getEntityData(jid, keys, profile)
 
 class Register(jsonrpc.JSONRPC):
     """This class manage the registration procedure with SàT
@@ -691,7 +692,7 @@
         self.bridge.register("connectionError", self.signal_handler.connectionError)
         self.bridge.register("actionResult", self.action_handler.actionResultCb) 
         #core
-        for signal_name in ['presenceUpdate', 'newMessage', 'subscribe', 'contactDeleted', 'newContact', 'updatedValue']:
+        for signal_name in ['presenceUpdate', 'newMessage', 'subscribe', 'contactDeleted', 'newContact', 'entityDataUpdated']:
             self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name))
         #plugins
         for signal_name in ['personalEvent', 'roomJoined', 'roomUserJoined', 'roomUserLeft', 'tarotGameStarted', 'tarotGameNew', 'tarotGameChooseContrat',