comparison src/memory/sqlite.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 069ad98b360d
comparison
equal deleted inserted replaced
1223:802b7e6bf098 1224:f0c9b149ed99
262 message, _type, extra_, self.profiles[profile])) 262 message, _type, extra_, self.profiles[profile]))
263 d.addErrback(lambda ignore: log.error(_("Can't save following message in history: from [%(from_jid)s] to [%(to_jid)s] ==> [%(message)s]" % 263 d.addErrback(lambda ignore: log.error(_("Can't save following message in history: from [%(from_jid)s] to [%(to_jid)s] ==> [%(message)s]" %
264 {"from_jid": from_jid.full(), "to_jid": to_jid.full(), "message": message}))) 264 {"from_jid": from_jid.full(), "to_jid": to_jid.full(), "message": message})))
265 return d 265 return d
266 266
267 def getHistory(self, from_jid, to_jid, limit=None, between=True, profile=None): 267 def getHistory(self, from_jid, to_jid, limit=None, between=True, search=None, profile=None):
268 """Retrieve messages in history 268 """Retrieve messages in history
269 @param from_jid (JID): source JID (full, or bare for catchall) 269 @param from_jid (JID): source JID (full, or bare for catchall)
270 @param to_jid (JID): dest JID (full, or bare for catchall) 270 @param to_jid (JID): dest JID (full, or bare for catchall)
271 @param limit (int): maximum number of messages to get: 271 @param limit (int): maximum number of messages to get:
272 - 0 for no message (returns the empty list) 272 - 0 for no message (returns the empty list)
273 - None for unlimited 273 - None for unlimited
274 @param between (bool): confound source and dest (ignore the direction) 274 @param between (bool): confound source and dest (ignore the direction)
275 @param search (str): pattern to filter the history results
275 @param profile (str): %(doc_profile)s 276 @param profile (str): %(doc_profile)s
276 @return: list of tuple as in http://wiki.goffi.org/wiki/Bridge_API#getHistory 277 @return: list of tuple as in http://wiki.goffi.org/wiki/Bridge_API#getHistory
277 """ 278 """
278 assert(profile) 279 assert(profile)
279 if limit == 0: 280 if limit == 0:
309 test_jid('source', to_jid), 310 test_jid('source', to_jid),
310 test_jid('dest', from_jid))) 311 test_jid('dest', from_jid)))
311 else: 312 else:
312 query_parts.append("%s AND %s" % (test_jid('source', from_jid), 313 query_parts.append("%s AND %s" % (test_jid('source', from_jid),
313 test_jid('dest', to_jid))) 314 test_jid('dest', to_jid)))
315 if search:
316 # TODO: use REGEXP (function to be defined) instead of GLOB: https://www.sqlite.org/lang_expr.html
317 query_parts.append("AND message GLOB ?")
318 values.append("*%s*" % search)
314 319
315 query_parts.append("ORDER BY timestamp DESC") 320 query_parts.append("ORDER BY timestamp DESC")
316 321
317 if limit is not None: 322 if limit is not None:
318 query_parts.append("LIMIT ?") 323 query_parts.append("LIMIT ?")