primitivus: basic handling of filter, only language can filtered for now
This commit is contained in:
parent
d3e2bef0cd
commit
e784c1694c
2 changed files with 29 additions and 0 deletions
|
|
@ -189,6 +189,7 @@ class Chat(PrimitivusWidget, quick_chat.QuickChat):
|
|||
|
||||
def __init__(self, host, target, type_=C.CHAT_ONE2ONE, occupants=None, subject=None, profiles=None):
|
||||
quick_chat.QuickChat.__init__(self, host, target, type_, occupants, subject, profiles=profiles)
|
||||
self.filters = [] # list of filter callbacks to apply
|
||||
self.mess_walker = urwid.SimpleListWalker([])
|
||||
self.mess_widgets = urwid.ListBox(self.mess_walker)
|
||||
self.chat_widget = urwid.Frame(self.mess_widgets)
|
||||
|
|
@ -268,6 +269,24 @@ class Chat(PrimitivusWidget, quick_chat.QuickChat):
|
|||
self.host.addMenus(menu, C.MENU_SINGLE, {'jid': full_jid})
|
||||
return menu
|
||||
|
||||
def setFilter(self, args):
|
||||
"""set filtering of messages
|
||||
|
||||
@param args(list[unicode]): filters following syntax "[filter]=[value]"
|
||||
empty list to clear all filters
|
||||
only lang=XX is handled for now
|
||||
"""
|
||||
if args:
|
||||
if args[0].startswith("lang="):
|
||||
lang = args[0][5:].strip()
|
||||
self.filters.append(lambda mess_data: lang in mess_data.message)
|
||||
else:
|
||||
del self.filters[:]
|
||||
|
||||
del self.mess_walker[:]
|
||||
for message in self.messages.itervalues():
|
||||
self.appendMessage(message)
|
||||
|
||||
def presenceListener(self, entity, show, priority, statuses, profile):
|
||||
"""Update entity's presence status
|
||||
|
||||
|
|
@ -307,6 +326,9 @@ class Chat(PrimitivusWidget, quick_chat.QuickChat):
|
|||
Can merge messages together is desirable (e.g.: multiple joined/leave)
|
||||
@param message(quick_chat.Message): message to add
|
||||
"""
|
||||
if self.filters:
|
||||
if not all([f(message) for f in self.filters]):
|
||||
return
|
||||
if self._user_moved(message):
|
||||
for wid in reversed(self.mess_walker):
|
||||
# we merge in/out messages if no message was sent meanwhile
|
||||
|
|
|
|||
|
|
@ -148,6 +148,13 @@ class EditBar(sat_widgets.ModalEdit):
|
|||
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)
|
||||
elif command == 'filter':
|
||||
# FIXME: filter is now only for current widget,
|
||||
# need to be able to set it globally or per widget
|
||||
widget = self.host.selected_widget
|
||||
# FIXME: Q&D way, need to be more generic
|
||||
if isinstance(widget, quick_chat.QuickChat):
|
||||
widget.setFilter(args)
|
||||
else:
|
||||
return
|
||||
self.set_edit_text('')
|
||||
|
|
|
|||
Loading…
Reference in a new issue