changeset 123:5cb852d9757e

use of async history
author Goffi <goffi@goffi.org>
date Sat, 10 Dec 2011 12:26:43 +0100
parents 397a88b340f3
children 6d1f4a3da29b
files browser_side/panels.py libervia.tac
diffstat 2 files changed, 17 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/browser_side/panels.py	Sat Dec 10 11:32:14 2011 +0100
+++ b/browser_side/panels.py	Sat Dec 10 12:26:43 2011 +0100
@@ -692,11 +692,10 @@
     def historyPrint(self, size=20):
         """Print the initial history"""
         def getHistoryCB(history):
-            stamps=history.keys()
-            stamps.sort()
-            for stamp in stamps:
-                self.printMessage(history[stamp][0], history[stamp][1], stamp)
-        self.host.bridge.call('getHistory', getHistoryCB, self.host.whoami.bare, self.target.bare, 20)
+            for line in history:
+                timestamp, from_jid, to_jid, message = line
+                self.printMessage(from_jid, message, timestamp)
+        self.host.bridge.call('getHistory', getHistoryCB, self.host.whoami.bare, self.target.bare, size, True)
    
     def printInfo(self, msg, type='normal'):
         """Print general info
--- a/libervia.tac	Sat Dec 10 11:32:14 2011 +0100
+++ b/libervia.tac	Sat Dec 10 12:26:43 2011 +0100
@@ -208,9 +208,8 @@
         profile = ISATSession(self.session).profile
         return self.sat_host.bridge.getPresenceStatus(profile) 
 
-    def jsonrpc_getHistory(self, from_jid, to_jid, size):
+    def jsonrpc_getHistory(self, from_jid, to_jid, size, between):
         """Return history for the from_jid/to_jid couple"""
-        #FIXME: this method should definitely be asynchrone, need to fix it !!!
         sat_session = ISATSession(self.session)
         profile = sat_session.profile
         sat_jid = sat_session.jid
@@ -220,7 +219,18 @@
         if JID(from_jid).userhost() != sat_jid.userhost() and JID(to_jid).userhost() != sat_jid.userhost():
             error("Trying to get history from a different jid, maybe a hack attempt ?")
             return {}
-        return self.sat_host.bridge.getHistory(from_jid, to_jid, size)
+        d = defer.Deferred()
+        self.sat_host.bridge.getHistory(from_jid, to_jid, size, between, callback=d.callback, errback=d.errback)
+        def show(result_dbus):
+            result = []
+            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)))
+            return result
+        d.addCallback(show)
+        return d
 
     def jsonrpc_joinMUC(self, room_jid, nick):
         """Join a Multi-User Chat room"""