Mercurial > libervia-web
diff libervia.tac @ 123:5cb852d9757e
use of async history
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 10 Dec 2011 12:26:43 +0100 |
parents | 2d40b0f5fb37 |
children | 6d1f4a3da29b |
line wrap: on
line diff
--- 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"""