# HG changeset patch # User Goffi # Date 1323516403 -3600 # Node ID 5cb852d9757eccac9d0254a5afdb94fefc5ed9b3 # Parent 397a88b340f3ea55ec04f35971720b1ee42e6d35 use of async history diff -r 397a88b340f3 -r 5cb852d9757e browser_side/panels.py --- 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 diff -r 397a88b340f3 -r 5cb852d9757e libervia.tac --- 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"""