diff --git a/slixfeed/action.py b/slixfeed/action.py index 598047f..30b6384 100644 --- a/slixfeed/action.py +++ b/slixfeed/action.py @@ -895,10 +895,10 @@ async def scan_json(db_file, url): ).format( title, summary, pathname) allow_list = await config.is_include_keyword( - db_file, "filter-allow", string) + db_file, "allow", string) if not allow_list: reject_list = await config.is_include_keyword( - db_file, "filter-deny", string) + db_file, "deny", string) if reject_list: read_status = 1 logging.debug( @@ -1176,10 +1176,10 @@ async def scan(db_file, url): ).format( title, summary, pathname) allow_list = await config.is_include_keyword( - db_file, "filter-allow", string) + db_file, "allow", string) if not allow_list: reject_list = await config.is_include_keyword( - db_file, "filter-deny", string) + db_file, "deny", string) if reject_list: read_status = 1 logging.debug( diff --git a/slixfeed/version.py b/slixfeed/version.py index 239b5cf..3a7b545 100644 --- a/slixfeed/version.py +++ b/slixfeed/version.py @@ -1,2 +1,2 @@ -__version__ = '0.1.5' -__version_info__ = (0, 1, 5) +__version__ = '0.1.6' +__version_info__ = (0, 1, 6) diff --git a/slixfeed/xmpp/client.py b/slixfeed/xmpp/client.py index a8bff8e..eb6f19c 100644 --- a/slixfeed/xmpp/client.py +++ b/slixfeed/xmpp/client.py @@ -456,6 +456,9 @@ class Slixfeed(slixmpp.ClientXMPP): self['xep_0050'].add_command(node='settings', name='Edit Settings', handler=self._handle_settings) + self['xep_0050'].add_command(node='filters', + name='Manage Filters', + handler=self._handle_filters) self['xep_0050'].add_command(node='subscriptions', name='Manage subscriptions', handler=self._handle_subscriptions) @@ -465,9 +468,80 @@ class Slixfeed(slixmpp.ClientXMPP): # self['xep_0050'].add_command(node='search', # name='Search', # handler=self._handle_search) - # self['xep_0050'].add_command(node='filters', - # name='Filters', - # handler=self._handle_filters) + + + async def _handle_filters(self, iq, session): + jid = session['from'].bare + jid_file = jid + db_file = config.get_pathname_to_database(jid_file) + form = self['xep_0004'].make_form('form', + 'Filters for {}'.format(jid)) + form['instructions'] = '🕸️ Manage filters' # 🪄️ + value = await sqlite.get_filters_value(db_file, 'allow') + form.add_field(var='allow', + ftype='text-single', + label='Allow list', + value=value, + desc=('Keywords to allow (comma-separated keywords).')) + value = await sqlite.get_filters_value(db_file, 'deny') + form.add_field(var='deny', + ftype='text-single', + label='Deny list', + value=value, + desc=('Keywords to deny (comma-separated keywords).')) + session['payload'] = form + session['next'] = self._handle_filters_complete + session['has_next'] = True + return session + + + async def _handle_filters_complete(self, payload, session): + """ + Process a command result from the user. + + Arguments: + payload -- Either a single item, such as a form, or a list + of items or forms if more than one form was + provided to the user. The payload may be any + stanza, such as jabber:x:oob for out of band + data, or jabber:x:data for typical data forms. + session -- A dictionary of data relevant to the command + session. Additional, custom data may be saved + here to persist across handler callbacks. + """ + # Text is not displayed; only labels + form = payload + + jid = session['from'].bare + form = self['xep_0004'].make_form('form', 'Filters for {}'.format(jid)) + form['instructions'] = ('🛡️ Filters have been updated') + jid_file = jid + db_file = config.get_pathname_to_database(jid_file) + # In this case (as is typical), the payload is a form + values = payload['values'] + for value in values: + key = value + val = values[value] + # NOTE We might want to add new keywords from + # an empty form instead of editing a form. + # keywords = await sqlite.get_filters_value(db_file, key) + keywords = '' + val = await config.add_to_list(val, keywords) + if await sqlite.get_filters_value(db_file, key): + await sqlite.update_filters_value(db_file, [key, val]) + else: + await sqlite.set_filters_value(db_file, [key, val]) + # result = '{}: {}'.format(key, val) + form.add_field(var=key + '_title', + ftype='fixed', + value=key.capitalize() + ' Filter') + form.add_field(var=key.capitalize() + ' list', + ftype='text-single', + value=val) + session['payload'] = form + session["has_next"] = False + session['next'] = None + return session async def _handle_subscriptions(self, iq, session):