diff src/memory/memory.py @ 1222:e6e0ea4dc835

memory: add Parameter "Chat history limit"
author souliane <souliane@mailoo.org>
date Wed, 24 Sep 2014 13:49:43 +0200
parents 5e5661ab5c81
children f0c9b149ed99
line wrap: on
line diff
--- a/src/memory/memory.py	Fri Oct 03 12:43:59 2014 +0200
+++ b/src/memory/memory.py	Wed Sep 24 13:49:43 2014 +0200
@@ -350,8 +350,25 @@
             extra = {}
         return self.storage.addToHistory(from_jid, to_jid, message, type_, extra, timestamp, profile)
 
-    def getHistory(self, from_jid, to_jid, limit=None, between=True, profile=C.PROF_KEY_NONE):
+    def getHistory(self, from_jid, to_jid, limit=C.HISTORY_LIMIT_NONE, between=True, profile=C.PROF_KEY_NONE):
+        """Retrieve messages in history
+        @param from_jid (JID): source JID (full, or bare for catchall)
+        @param to_jid (JID): dest JID (full, or bare for catchall)
+        @param limit (int): maximum number of messages to get:
+            - 0 for no message (returns the empty list)
+            - C.HISTORY_LIMIT_NONE or None for unlimited
+            - C.HISTORY_LIMIT_DEFAULT to use the HISTORY_LIMIT parameter value
+        @param between (bool): confound source and dest (ignore the direction)
+        @param profile (str): %(doc_profile)s
+        @return: list of tuple as in http://wiki.goffi.org/wiki/Bridge_API#getHistory
+        """
         assert profile != C.PROF_KEY_NONE
+        if limit == C.HISTORY_LIMIT_DEFAULT:
+            limit = int(self.getParamA(C.HISTORY_LIMIT, 'General', profile_key=profile))
+        elif limit == C.HISTORY_LIMIT_NONE:
+            limit = None
+        if limit == 0:
+            return defer.succeed([])
         return self.storage.getHistory(jid.JID(from_jid), jid.JID(to_jid), limit, between, profile)
 
     def _getLastResource(self, jid_s, profile_key):