comparison frontends/src/quick_frontend/quick_chat.py @ 2013:b536dd121da1

backend (memory), frontends: improved history filtering: a "filters" dictionnary is now use to filter, it can have, for now, filtering on: - "body": filter only on the body (equivalent to former "search" parameter, but not case sensitive) - "search": fitler on body + source resource - "types": allowed types - "not_types": forbidden types primitivus now do searching using "search", i.e. source resource is now taken into account (and search is now case insensitive)
author Goffi <goffi@goffi.org>
date Mon, 18 Jul 2016 00:52:02 +0200
parents 19b9d3f8a6c7
children 20fb71b656e3
comparison
equal deleted inserted replaced
2012:53587e738aca 2013:b536dd121da1
276 else: 276 else:
277 if mess_type != C.MESS_TYPE_GROUPCHAT and entity in self.targets: 277 if mess_type != C.MESS_TYPE_GROUPCHAT and entity in self.targets:
278 return True 278 return True
279 return False 279 return False
280 280
281 def updateHistory(self, size=C.HISTORY_LIMIT_DEFAULT, search='', profile='@NONE@'): 281 def updateHistory(self, size=C.HISTORY_LIMIT_DEFAULT, filters=None, profile='@NONE@'):
282 """Called when history need to be recreated 282 """Called when history need to be recreated
283 283
284 Remove all message from history then call historyPrint 284 Remove all message from history then call historyPrint
285 Must probably be overriden by frontend to clear widget 285 Must probably be overriden by frontend to clear widget
286 @param size (int): number of messages 286 @param size (int): number of messages
287 @param search (str): pattern to filter the history results 287 @param filters (str): patterns to filter the history results
288 @param profile (str): %(doc_profile)s 288 @param profile (str): %(doc_profile)s
289 """ 289 """
290 self._locked = True 290 self._locked = True
291 self.messages.clear() 291 self.messages.clear()
292 self.historyPrint(size, search, profile) 292 self.historyPrint(size, filters, profile)
293 293
294 def _onHistoryPrinted(self): 294 def _onHistoryPrinted(self):
295 """Method called when history is printed (or failed) 295 """Method called when history is printed (or failed)
296 296
297 unlock the widget, and can be used to refresh or scroll down 297 unlock the widget, and can be used to refresh or scroll down
299 """ 299 """
300 self._locked = False 300 self._locked = False
301 for data in self._cache: 301 for data in self._cache:
302 self.messageNew(*data) 302 self.messageNew(*data)
303 303
304 def historyPrint(self, size=C.HISTORY_LIMIT_DEFAULT, search='', profile='@NONE@'): 304 def historyPrint(self, size=C.HISTORY_LIMIT_DEFAULT, filters=None, profile='@NONE@'):
305 """Print the current history 305 """Print the current history
306 306
307 @param size (int): number of messages 307 @param size (int): number of messages
308 @param search (str): pattern to filter the history results 308 @param search (str): pattern to filter the history results
309 @param profile (str): %(doc_profile)s 309 @param profile (str): %(doc_profile)s
310 """ 310 """
311 if filters is None:
312 filters = {}
311 if size == 0: 313 if size == 0:
312 log.debug(u"Empty history requested, skipping") 314 log.debug(u"Empty history requested, skipping")
313 self._onHistoryPrinted() 315 self._onHistoryPrinted()
314 return 316 return
315 log_msg = _(u"now we print the history") 317 log_msg = _(u"now we print the history")
338 340
339 def _historyGetEb(err): 341 def _historyGetEb(err):
340 log.error(_(u"Can't get history")) 342 log.error(_(u"Can't get history"))
341 self._onHistoryPrinted() 343 self._onHistoryPrinted()
342 344
343 self.host.bridge.historyGet(unicode(self.host.profiles[profile].whoami.bare), unicode(target), size, True, search, profile, callback=_historyGetCb, errback=_historyGetEb) 345 self.host.bridge.historyGet(unicode(self.host.profiles[profile].whoami.bare), unicode(target), size, True, filters, profile, callback=_historyGetCb, errback=_historyGetEb)
344 346
345 def messageNew(self, uid, timestamp, from_jid, to_jid, msg, subject, type_, extra, profile): 347 def messageNew(self, uid, timestamp, from_jid, to_jid, msg, subject, type_, extra, profile):
346 log.debug(u"messageNew ==> {}".format((uid, timestamp, from_jid, to_jid, msg, subject, type_, extra, profile))) 348 log.debug(u"messageNew ==> {}".format((uid, timestamp, from_jid, to_jid, msg, subject, type_, extra, profile)))
347 if self._locked: 349 if self._locked:
348 self._cache.append(uid, timestamp, from_jid, to_jid, msg, subject, type_, extra, profile) 350 self._cache.append(uid, timestamp, from_jid, to_jid, msg, subject, type_, extra, profile)