Mercurial > libervia-backend
comparison frontends/src/primitivus/chat.py @ 1966:d727aab9a80e
primitivus: basic handling of filter, only language can filtered for now
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 20 Jun 2016 19:19:16 +0200 |
parents | a2bc5089c2eb |
children | de6faf9be715 |
comparison
equal
deleted
inserted
replaced
1965:4c5d8cd35690 | 1966:d727aab9a80e |
---|---|
187 | 187 |
188 class Chat(PrimitivusWidget, quick_chat.QuickChat): | 188 class Chat(PrimitivusWidget, quick_chat.QuickChat): |
189 | 189 |
190 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, occupants=None, subject=None, profiles=None): | 190 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, occupants=None, subject=None, profiles=None): |
191 quick_chat.QuickChat.__init__(self, host, target, type_, occupants, subject, profiles=profiles) | 191 quick_chat.QuickChat.__init__(self, host, target, type_, occupants, subject, profiles=profiles) |
192 self.filters = [] # list of filter callbacks to apply | |
192 self.mess_walker = urwid.SimpleListWalker([]) | 193 self.mess_walker = urwid.SimpleListWalker([]) |
193 self.mess_widgets = urwid.ListBox(self.mess_walker) | 194 self.mess_widgets = urwid.ListBox(self.mess_walker) |
194 self.chat_widget = urwid.Frame(self.mess_widgets) | 195 self.chat_widget = urwid.Frame(self.mess_widgets) |
195 self.chat_colums = urwid.Columns([('weight', 8, self.chat_widget)]) | 196 self.chat_colums = urwid.Columns([('weight', 8, self.chat_widget)]) |
196 self.pile = urwid.Pile([self.chat_colums]) | 197 self.pile = urwid.Pile([self.chat_colums]) |
266 else: | 267 else: |
267 full_jid = self.target | 268 full_jid = self.target |
268 self.host.addMenus(menu, C.MENU_SINGLE, {'jid': full_jid}) | 269 self.host.addMenus(menu, C.MENU_SINGLE, {'jid': full_jid}) |
269 return menu | 270 return menu |
270 | 271 |
272 def setFilter(self, args): | |
273 """set filtering of messages | |
274 | |
275 @param args(list[unicode]): filters following syntax "[filter]=[value]" | |
276 empty list to clear all filters | |
277 only lang=XX is handled for now | |
278 """ | |
279 if args: | |
280 if args[0].startswith("lang="): | |
281 lang = args[0][5:].strip() | |
282 self.filters.append(lambda mess_data: lang in mess_data.message) | |
283 else: | |
284 del self.filters[:] | |
285 | |
286 del self.mess_walker[:] | |
287 for message in self.messages.itervalues(): | |
288 self.appendMessage(message) | |
289 | |
271 def presenceListener(self, entity, show, priority, statuses, profile): | 290 def presenceListener(self, entity, show, priority, statuses, profile): |
272 """Update entity's presence status | 291 """Update entity's presence status |
273 | 292 |
274 @param entity (jid.JID): entity updated | 293 @param entity (jid.JID): entity updated |
275 @param show: availability | 294 @param show: availability |
305 """Create a MessageWidget and append it | 324 """Create a MessageWidget and append it |
306 | 325 |
307 Can merge messages together is desirable (e.g.: multiple joined/leave) | 326 Can merge messages together is desirable (e.g.: multiple joined/leave) |
308 @param message(quick_chat.Message): message to add | 327 @param message(quick_chat.Message): message to add |
309 """ | 328 """ |
329 if self.filters: | |
330 if not all([f(message) for f in self.filters]): | |
331 return | |
310 if self._user_moved(message): | 332 if self._user_moved(message): |
311 for wid in reversed(self.mess_walker): | 333 for wid in reversed(self.mess_walker): |
312 # we merge in/out messages if no message was sent meanwhile | 334 # we merge in/out messages if no message was sent meanwhile |
313 if not isinstance(wid, MessageWidget): | 335 if not isinstance(wid, MessageWidget): |
314 continue | 336 continue |