comparison 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
comparison
equal deleted inserted replaced
1221:5e5661ab5c81 1222:e6e0ea4dc835
348 assert profile != C.PROF_KEY_NONE 348 assert profile != C.PROF_KEY_NONE
349 if extra is None: 349 if extra is None:
350 extra = {} 350 extra = {}
351 return self.storage.addToHistory(from_jid, to_jid, message, type_, extra, timestamp, profile) 351 return self.storage.addToHistory(from_jid, to_jid, message, type_, extra, timestamp, profile)
352 352
353 def getHistory(self, from_jid, to_jid, limit=None, between=True, profile=C.PROF_KEY_NONE): 353 def getHistory(self, from_jid, to_jid, limit=C.HISTORY_LIMIT_NONE, between=True, profile=C.PROF_KEY_NONE):
354 """Retrieve messages in history
355 @param from_jid (JID): source JID (full, or bare for catchall)
356 @param to_jid (JID): dest JID (full, or bare for catchall)
357 @param limit (int): maximum number of messages to get:
358 - 0 for no message (returns the empty list)
359 - C.HISTORY_LIMIT_NONE or None for unlimited
360 - C.HISTORY_LIMIT_DEFAULT to use the HISTORY_LIMIT parameter value
361 @param between (bool): confound source and dest (ignore the direction)
362 @param profile (str): %(doc_profile)s
363 @return: list of tuple as in http://wiki.goffi.org/wiki/Bridge_API#getHistory
364 """
354 assert profile != C.PROF_KEY_NONE 365 assert profile != C.PROF_KEY_NONE
366 if limit == C.HISTORY_LIMIT_DEFAULT:
367 limit = int(self.getParamA(C.HISTORY_LIMIT, 'General', profile_key=profile))
368 elif limit == C.HISTORY_LIMIT_NONE:
369 limit = None
370 if limit == 0:
371 return defer.succeed([])
355 return self.storage.getHistory(jid.JID(from_jid), jid.JID(to_jid), limit, between, profile) 372 return self.storage.getHistory(jid.JID(from_jid), jid.JID(to_jid), limit, between, profile)
356 373
357 def _getLastResource(self, jid_s, profile_key): 374 def _getLastResource(self, jid_s, profile_key):
358 jid_ = jid.JID(jid_s) 375 jid_ = jid.JID(jid_s)
359 return self.getLastResource(jid_, profile_key) or "" 376 return self.getLastResource(jid_, profile_key) or ""