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)
This commit is contained in:
Goffi 2016-07-18 00:52:02 +02:00
commit 9647e90943
4 changed files with 58 additions and 36 deletions

View file

@ -508,14 +508,14 @@ class DBusBridgeFrontend(BridgeFrontend):
kwargs['error_handler'] = error_handler
return self.db_core_iface.getWaitingSub(profile_key, **kwargs)
def historyGet(self, from_jid, to_jid, limit, between=True, search='', profile="@NONE@", callback=None, errback=None):
def historyGet(self, from_jid, to_jid, limit, between=True, filters='', profile="@NONE@", callback=None, errback=None):
if callback is None:
error_handler = None
else:
if errback is None:
errback = log.error
error_handler = lambda err:errback(dbus_to_bridge_exception(err))
return self.db_core_iface.historyGet(from_jid, to_jid, limit, between, search, profile, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
return self.db_core_iface.historyGet(from_jid, to_jid, limit, between, filters, profile, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
def isConnected(self, profile_key="@DEFAULT@", callback=None, errback=None):
if callback is None:

View file

@ -540,12 +540,12 @@ class Chat(PrimitivusWidget, quick_chat.QuickChat):
except AttributeError:
pass
def updateHistory(self, size=C.HISTORY_LIMIT_DEFAULT, search='', profile='@NONE@'):
def updateHistory(self, size=C.HISTORY_LIMIT_DEFAULT, filters=None, profile='@NONE@'):
del self.mess_walker[:]
if search:
self.mess_walker.append(urwid.Text(_(u"Results for searching the globbing pattern: {}").format(search)))
self.mess_walker.append(urwid.Text(_(u"Type ':history <lines>' to reset the chat history").format(search)))
super(Chat, self).updateHistory(size, search, profile)
if filters and 'search' in filters:
self.mess_walker.append(urwid.Text(_(u"Results for searching the globbing pattern: {}").format(filters['search'])))
self.mess_walker.append(urwid.Text(_(u"Type ':history <lines>' to reset the chat history")))
super(Chat, self).updateHistory(size, filters, profile)
def _onHistoryPrinted(self):
"""Refresh or scroll down the focus after the history is printed"""

View file

@ -130,7 +130,7 @@ class EditBar(sat_widgets.ModalEdit):
if not pattern:
self.host.notif_bar.addMessage(D_("Please specify the globbing pattern to search for"))
else:
widget.updateHistory(size=C.HISTORY_LIMIT_NONE, search=pattern, profile=widget.profile)
widget.updateHistory(size=C.HISTORY_LIMIT_NONE, filters={'search': pattern}, profile=widget.profile)
elif command == 'filter':
# FIXME: filter is now only for current widget,
# need to be able to set it globally or per widget

View file

@ -278,18 +278,18 @@ class QuickChat(quick_widgets.QuickWidget):
return True
return False
def updateHistory(self, size=C.HISTORY_LIMIT_DEFAULT, search='', profile='@NONE@'):
def updateHistory(self, size=C.HISTORY_LIMIT_DEFAULT, filters=None, profile='@NONE@'):
"""Called when history need to be recreated
Remove all message from history then call historyPrint
Must probably be overriden by frontend to clear widget
@param size (int): number of messages
@param search (str): pattern to filter the history results
@param filters (str): patterns to filter the history results
@param profile (str): %(doc_profile)s
"""
self._locked = True
self.messages.clear()
self.historyPrint(size, search, profile)
self.historyPrint(size, filters, profile)
def _onHistoryPrinted(self):
"""Method called when history is printed (or failed)
@ -301,13 +301,15 @@ class QuickChat(quick_widgets.QuickWidget):
for data in self._cache:
self.messageNew(*data)
def historyPrint(self, size=C.HISTORY_LIMIT_DEFAULT, search='', profile='@NONE@'):
def historyPrint(self, size=C.HISTORY_LIMIT_DEFAULT, filters=None, profile='@NONE@'):
"""Print the current history
@param size (int): number of messages
@param search (str): pattern to filter the history results
@param profile (str): %(doc_profile)s
"""
if filters is None:
filters = {}
if size == 0:
log.debug(u"Empty history requested, skipping")
self._onHistoryPrinted()
@ -340,7 +342,7 @@ class QuickChat(quick_widgets.QuickWidget):
log.error(_(u"Can't get history"))
self._onHistoryPrinted()
self.host.bridge.historyGet(unicode(self.host.profiles[profile].whoami.bare), unicode(target), size, True, search, profile, callback=_historyGetCb, errback=_historyGetEb)
self.host.bridge.historyGet(unicode(self.host.profiles[profile].whoami.bare), unicode(target), size, True, filters, profile, callback=_historyGetCb, errback=_historyGetEb)
def messageNew(self, uid, timestamp, from_jid, to_jid, msg, subject, type_, extra, profile):
log.debug(u"messageNew ==> {}".format((uid, timestamp, from_jid, to_jid, msg, subject, type_, extra, profile)))