Mercurial > libervia-backend
changeset 448:17c7e48bf68f
core: - history management improved
- better timestamp precision for history
bridge + core: history signature change (now return a list instead of a dict, and timestamp is now float)
quick_frontend: - use of new history API
- removed deprecated keep_last argument in getHistory (was only used by Sortilège)
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 04 Dec 2011 16:18:56 +0100 |
parents | 485a6d125498 |
children | 961543b20806 |
files | frontends/src/quick_frontend/quick_chat.py src/bridge/DBus.py src/bridge/bridge_constructor/bridge_template.ini src/memory/sqlite.py |
diffstat | 4 files changed, 20 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_chat.py Sun Dec 04 00:58:20 2011 +0100 +++ b/frontends/src/quick_frontend/quick_chat.py Sun Dec 04 16:18:56 2011 +0100 @@ -84,21 +84,18 @@ error (_("[INTERNAL] trying to set subject for a non group chat window")) raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here - def historyPrint(self, size=20, keep_last=False, profile='@NONE@'): + def historyPrint(self, size=20, profile='@NONE@'): """Print the initial history""" debug (_("now we print history")) def onHistory(history): - stamps=history.keys() - stamps.sort() - for stamp in stamps: - from_jid, to_jid, message = history[stamp] - self.printMessage(JID(from_jid), message, profile, stamp) - if keep_last: ##FIXME hack for sortilege - self.last_history = stamps[-1] if stamps else None + for line in history: + timestamp, from_jid, to_jid, message = line + self.printMessage(JID(from_jid), message, profile, timestamp) + def onHistoryError(err): error (_("Can't get history")) - history=self.host.bridge.getHistory(self.host.profiles[profile]['whoami'].short, self.target.short, 20, callback=onHistory, errback=onHistoryError) + self.host.bridge.getHistory(self.host.profiles[profile]['whoami'].short, self.target.short, 20, callback=onHistory, errback=onHistoryError) def _get_nick(self, jid): """Return nick of this jid when possible"""
--- a/src/bridge/DBus.py Sun Dec 04 00:58:20 2011 +0100 +++ b/src/bridge/DBus.py Sun Dec 04 16:18:56 2011 +0100 @@ -252,7 +252,7 @@ return self._callback("getContacts", unicode(profile_key)) @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, - in_signature='ssib', out_signature='a{i(sss)}', + in_signature='ssib', out_signature='a(dsss)', async_callbacks=('callback', 'errback')) def getHistory(self, from_jid, to_jid, limit, between=True, callback=None, errback=None): return self._callback("getHistory", unicode(from_jid), unicode(to_jid), limit, between, callback=callback, errback=errback)
--- a/src/bridge/bridge_constructor/bridge_template.ini Sun Dec 04 00:58:20 2011 +0100 +++ b/src/bridge/bridge_constructor/bridge_template.ini Sun Dec 04 16:18:56 2011 +0100 @@ -438,14 +438,14 @@ type=method category=core sig_in=ssib -sig_out=a{i(sss)} +sig_out=a(dsss) param_3_default=True doc=Get history of a communication between two entities doc_param_0=from_jid: source JID (bare jid for catch all, full jid else) doc_param_1=to_jid: dest JID (bare jid for catch all, full jid else) doc_param_2=limit: max number of history elements to get (0 for the whole history) doc_param_3=between: True if we want history between the two jids (in both direction), False if we only want messages from from_jid to to_jid -doc_return=Dict where key is timestamp (seconds this the Epoch), and value is a tuple (full from_jid, full to_jid, message) +doc_return=Ordered list (by timestamp) of tuples (timestamp, full from_jid, full to_jid, message) [addContact] type=method
--- a/src/memory/sqlite.py Sun Dec 04 00:58:20 2011 +0100 +++ b/src/memory/sqlite.py Sun Dec 04 16:18:56 2011 +0100 @@ -178,7 +178,7 @@ """ assert(profile!=None) d = self.dbpool.runQuery("INSERT INTO history(source, source_res, dest, dest_res, timestamp, message, profile_id) VALUES (?,?,?,?,?,?,?)", - (from_jid.userhost(), from_jid.resource, to_jid.userhost(), to_jid.resource, timestamp or int(time.time()), + (from_jid.userhost(), from_jid.resource, to_jid.userhost(), to_jid.resource, timestamp or time.time(), message, self.profiles[profile])) d.addErrback(lambda ignore: error(_("Can't save following message in history: from [%(from_jid)s] to [%(to_jid)s] ==> [%(message)s]" % {"from_jid":from_jid.full(), "to_jid":to_jid.full(), "message":message}))) @@ -190,14 +190,15 @@ @param to_jid: dest JID (full, or bare for catchall @param size: maximum number of messages to get, or 0 for unlimited """ - def sqliteToDict(result): - result_dict = {} - for row in result: + def sqliteToDict(query_result): + query_result.reverse() + result = [] + for row in query_result: timestamp, source, source_res, dest, dest_res, message = row - result_dict[timestamp] = ("%s/%s" % (source, source_res) if source_res else source, + result.append((timestamp, "%s/%s" % (source, source_res) if source_res else source, "%s/%s" % (dest, dest_res) if dest_res else dest, - message) - return result_dict + message)) + return result query_parts = ["SELECT timestamp, source, source_res, dest, dest_res, message FROM history WHERE"] values = [] @@ -214,6 +215,9 @@ if to_jid.resource: query_parts.append("AND dest_res=?") values.append(to_jid.resource) + + query_parts.append("ORDER BY timestamp DESC") + if limit: query_parts.append("LIMIT ?") values.append(limit)