changeset 1221:5e5661ab5c81

memory: getHistory with limit=0 now returns an empty list, use limit=None to return all messages
author souliane <souliane@mailoo.org>
date Fri, 03 Oct 2014 12:43:59 +0200
parents f91e7028e2c3
children e6e0ea4dc835
files src/memory/memory.py src/memory/sqlite.py
diffstat 2 files changed, 6 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/memory/memory.py	Fri Oct 03 12:27:43 2014 +0200
+++ b/src/memory/memory.py	Fri Oct 03 12:43:59 2014 +0200
@@ -350,7 +350,7 @@
             extra = {}
         return self.storage.addToHistory(from_jid, to_jid, message, type_, extra, timestamp, profile)
 
-    def getHistory(self, from_jid, to_jid, limit=0, between=True, profile=C.PROF_KEY_NONE):
+    def getHistory(self, from_jid, to_jid, limit=None, between=True, profile=C.PROF_KEY_NONE):
         assert profile != C.PROF_KEY_NONE
         return self.storage.getHistory(jid.JID(from_jid), jid.JID(to_jid), limit, between, profile)
 
--- a/src/memory/sqlite.py	Fri Oct 03 12:27:43 2014 +0200
+++ b/src/memory/sqlite.py	Fri Oct 03 12:43:59 2014 +0200
@@ -264,13 +264,15 @@
                                           {"from_jid": from_jid.full(), "to_jid": to_jid.full(), "message": message})))
         return d
 
-    def getHistory(self, from_jid, to_jid, limit=0, between=True, profile=None):
+    def getHistory(self, from_jid, to_jid, limit=None, between=True, profile=None):
         """Store a new message in history
         @param from_jid: source JID (full, or bare for catchall
         @param to_jid: dest JID (full, or bare for catchall
-        @param size: maximum number of messages to get, or 0 for unlimited
+        @param size: maximum number of messages to get, or None for unlimited
         """
         assert(profile)
+        if limit == 0:
+            return defer.succeed([])
 
         def sqliteToList(query_result):
             query_result.reverse()
@@ -307,7 +309,7 @@
 
         query_parts.append("ORDER BY timestamp DESC")
 
-        if limit:
+        if limit is not None:
             query_parts.append("LIMIT ?")
             values.append(limit)