comparison src/memory/memory.py @ 1224:f0c9b149ed99

bridge, memory: add "search" attribute to getHistory (filter the results with a unix globbing pattern)
author souliane <souliane@mailoo.org>
date Sat, 04 Oct 2014 10:25:32 +0200
parents e6e0ea4dc835
children 9c17bd37e6e5
comparison
equal deleted inserted replaced
1223:802b7e6bf098 1224:f0c9b149ed99
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=C.HISTORY_LIMIT_NONE, between=True, profile=C.PROF_KEY_NONE): 353 def getHistory(self, from_jid, to_jid, limit=C.HISTORY_LIMIT_NONE, between=True, search=None, profile=C.PROF_KEY_NONE):
354 """Retrieve messages in history 354 """Retrieve messages in history
355 @param from_jid (JID): source JID (full, or bare for catchall) 355 @param from_jid (JID): source JID (full, or bare for catchall)
356 @param to_jid (JID): dest 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: 357 @param limit (int): maximum number of messages to get:
358 - 0 for no message (returns the empty list) 358 - 0 for no message (returns the empty list)
359 - C.HISTORY_LIMIT_NONE or None for unlimited 359 - C.HISTORY_LIMIT_NONE or None for unlimited
360 - C.HISTORY_LIMIT_DEFAULT to use the HISTORY_LIMIT parameter value 360 - C.HISTORY_LIMIT_DEFAULT to use the HISTORY_LIMIT parameter value
361 @param between (bool): confound source and dest (ignore the direction) 361 @param between (bool): confound source and dest (ignore the direction)
362 @param search (str): pattern to filter the history results
362 @param profile (str): %(doc_profile)s 363 @param profile (str): %(doc_profile)s
363 @return: list of tuple as in http://wiki.goffi.org/wiki/Bridge_API#getHistory 364 @return: list of tuple as in http://wiki.goffi.org/wiki/Bridge_API#getHistory
364 """ 365 """
365 assert profile != C.PROF_KEY_NONE 366 assert profile != C.PROF_KEY_NONE
366 if limit == C.HISTORY_LIMIT_DEFAULT: 367 if limit == C.HISTORY_LIMIT_DEFAULT:
367 limit = int(self.getParamA(C.HISTORY_LIMIT, 'General', profile_key=profile)) 368 limit = int(self.getParamA(C.HISTORY_LIMIT, 'General', profile_key=profile))
368 elif limit == C.HISTORY_LIMIT_NONE: 369 elif limit == C.HISTORY_LIMIT_NONE:
369 limit = None 370 limit = None
370 if limit == 0: 371 if limit == 0:
371 return defer.succeed([]) 372 return defer.succeed([])
372 return self.storage.getHistory(jid.JID(from_jid), jid.JID(to_jid), limit, between, profile) 373 return self.storage.getHistory(jid.JID(from_jid), jid.JID(to_jid), limit, between, search, profile)
373 374
374 def _getLastResource(self, jid_s, profile_key): 375 def _getLastResource(self, jid_s, profile_key):
375 jid_ = jid.JID(jid_s) 376 jid_ = jid.JID(jid_s)
376 return self.getLastResource(jid_, profile_key) or "" 377 return self.getLastResource(jid_, profile_key) or ""
377 378