comparison 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
comparison
equal deleted inserted replaced
122:397a88b340f3 123:5cb852d9757e
206 def jsonrpc_getPresenceStatus(self): 206 def jsonrpc_getPresenceStatus(self):
207 """Get Presence information for connected contacts""" 207 """Get Presence information for connected contacts"""
208 profile = ISATSession(self.session).profile 208 profile = ISATSession(self.session).profile
209 return self.sat_host.bridge.getPresenceStatus(profile) 209 return self.sat_host.bridge.getPresenceStatus(profile)
210 210
211 def jsonrpc_getHistory(self, from_jid, to_jid, size): 211 def jsonrpc_getHistory(self, from_jid, to_jid, size, between):
212 """Return history for the from_jid/to_jid couple""" 212 """Return history for the from_jid/to_jid couple"""
213 #FIXME: this method should definitely be asynchrone, need to fix it !!!
214 sat_session = ISATSession(self.session) 213 sat_session = ISATSession(self.session)
215 profile = sat_session.profile 214 profile = sat_session.profile
216 sat_jid = sat_session.jid 215 sat_jid = sat_session.jid
217 if not sat_jid: 216 if not sat_jid:
218 error("No jid saved for this profile") 217 error("No jid saved for this profile")
219 return {} 218 return {}
220 if JID(from_jid).userhost() != sat_jid.userhost() and JID(to_jid).userhost() != sat_jid.userhost(): 219 if JID(from_jid).userhost() != sat_jid.userhost() and JID(to_jid).userhost() != sat_jid.userhost():
221 error("Trying to get history from a different jid, maybe a hack attempt ?") 220 error("Trying to get history from a different jid, maybe a hack attempt ?")
222 return {} 221 return {}
223 return self.sat_host.bridge.getHistory(from_jid, to_jid, size) 222 d = defer.Deferred()
223 self.sat_host.bridge.getHistory(from_jid, to_jid, size, between, callback=d.callback, errback=d.errback)
224 def show(result_dbus):
225 result = []
226 for line in result_dbus:
227 #XXX: we have to do this stupid thing because Python D-Bus use its own types instead of standard types
228 # and txJsonRPC doesn't accept D-Bus types, resulting in a empty query
229 timestamp, from_jid, to_jid, message = line
230 result.append((float(timestamp), unicode(from_jid), unicode(to_jid), unicode(message)))
231 return result
232 d.addCallback(show)
233 return d
224 234
225 def jsonrpc_joinMUC(self, room_jid, nick): 235 def jsonrpc_joinMUC(self, room_jid, nick):
226 """Join a Multi-User Chat room""" 236 """Join a Multi-User Chat room"""
227 profile = ISATSession(self.session).profile 237 profile = ISATSession(self.session).profile
228 try: 238 try: