Improve About form.

Improve handling of setting change.
This commit is contained in:
Schimon Jehudah 2024-03-09 19:03:18 +00:00
parent 8d9b060314
commit e553166954
9 changed files with 1008 additions and 614 deletions

View file

@ -54,11 +54,15 @@ from slixfeed.xmpp.presence import XmppPresence
from slixfeed.xmpp.upload import XmppUpload from slixfeed.xmpp.upload import XmppUpload
from slixfeed.xmpp.utility import get_chat_type from slixfeed.xmpp.utility import get_chat_type
import sys import sys
import tomllib
from urllib import error from urllib import error
from urllib.parse import parse_qs, urlsplit from urllib.parse import parse_qs, urlsplit
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
try:
import tomllib
except:
import tomli as tomllib
logger = Logger(__name__) logger = Logger(__name__)
try: try:
@ -655,10 +659,12 @@ def list_feeds(results):
.format(len(results))) .format(len(results)))
else: else:
url = pick_a_feed() url = pick_a_feed()
message = ('List of subscriptions is empty. To add a feed, send a URL.' message = ('List of subscriptions is empty.'
'Featured feed:\n*{}*\n{}' '\n'
.format(url['name'], 'To add a feed, send a URL.'
url['link'])) '\n'
'Featured news:\n*{}*\n{}'
.format(url['name'], url['link']))
return message return message

View file

@ -76,6 +76,12 @@ name = "classless Kulla"
link = "https://www.classless.org/feed/atom/" link = "https://www.classless.org/feed/atom/"
tags = ["europe ,germany ,history ,literature ,war"] tags = ["europe ,germany ,history ,literature ,war"]
[[feeds]]
lang = "de-de"
name = "Die Unbestechlichen"
link = "https://dieunbestechlichen.com/feed/"
tags = ["culture", "germany", "local", "news"]
[[feeds]] [[feeds]]
lang = "de-de" lang = "de-de"
name = "Digitalcourage" name = "Digitalcourage"
@ -286,6 +292,12 @@ name = "Ctrl blog"
link = "https://feed.ctrl.blog/latest.atom" link = "https://feed.ctrl.blog/latest.atom"
tags = ["computer", "technology"] tags = ["computer", "technology"]
[[feeds]]
lang = "en-us"
name = "Delta Chat - Messenger based on e-mail"
link = "https://delta.chat/feed.xml"
tags = ["email", "telecommunication"]
[[feeds]] [[feeds]]
lang = "en-us" lang = "en-us"
name = "Disroot Blog" name = "Disroot Blog"
@ -478,6 +490,12 @@ name = "Project Gemini news"
link = "https://gemini.circumlunar.space/news/atom.xml" link = "https://gemini.circumlunar.space/news/atom.xml"
tags = ["gemini", "internet"] tags = ["gemini", "internet"]
[[feeds]]
lang = "en-us"
name = "Public Intelligence Blog"
link = "https://phibetaiota.net/feed/"
tags = ["cia", "conspiracy", "health", "government", "war"]
[[feeds]] [[feeds]]
lang = "en-us" lang = "en-us"
name = "PUNCH" name = "PUNCH"
@ -578,13 +596,7 @@ tags = ["3d", "architecture", "design", "game"]
lang = "en-us" lang = "en-us"
name = "Take Back Our Tech" name = "Take Back Our Tech"
link = "https://takebackourtech.org/rss/" link = "https://takebackourtech.org/rss/"
tags = ["internet", "privacy", "surveillance"] tags = ["computer", "internet", "privacy", "surveillance"]
[[feeds]]
lang = "en-us"
name = "The Bald Brothers"
link = "https://thebaldbrothers.com/feed/"
tags = ["lifestyle", "men"]
[[feeds]] [[feeds]]
lang = "en-us" lang = "en-us"
@ -592,12 +604,24 @@ name = "The 250kb Club"
link = "https://250kb.club/rss.xml" link = "https://250kb.club/rss.xml"
tags = ["webring"] tags = ["webring"]
[[feeds]]
lang = "en-us"
name = "The Bald Brothers"
link = "https://thebaldbrothers.com/feed/"
tags = ["lifestyle", "men"]
[[feeds]] [[feeds]]
lang = "en-us" lang = "en-us"
name = "The Conscious Resistance Network" name = "The Conscious Resistance Network"
link = "https://theconsciousresistance.com/feed/" link = "https://theconsciousresistance.com/feed/"
tags = ["culture", "government", "podcast", "politics", "privacy", "surveillance", "usa"] tags = ["culture", "government", "podcast", "politics", "privacy", "surveillance", "usa"]
[[feeds]]
lang = "en-us"
name = "Lazy Reading | The Cyber Vanguard"
link = "https://cyber.dabamos.de/blog/feed.rss"
tags = ["computer", "internet", "linux", "software", "telecommunication"]
[[feeds]] [[feeds]]
lang = "en-us" lang = "en-us"
name = "The Corbett Report" name = "The Corbett Report"

File diff suppressed because it is too large Load diff

View file

@ -80,6 +80,14 @@ class Config:
else: else:
await sqlite.set_setting_value(db_file, key_val) await sqlite.set_setting_value(db_file, key_val)
def get_setting_value(settings, jid_bare, key):
if key in settings[jid_bare]:
value = settings[jid_bare][key]
else:
value = settings['default'][key]
return value
# self.settings = {} # self.settings = {}
# initiate an empty dict and the rest would be: # initiate an empty dict and the rest would be:
# settings['account'] = {} # settings['account'] = {}

View file

@ -1,2 +1,2 @@
__version__ = '0.1.34' __version__ = '0.1.35'
__version_info__ = (0, 1, 34) __version_info__ = (0, 1, 35)

View file

@ -59,6 +59,11 @@ from slixfeed.xmpp.utility import get_chat_type
import sys import sys
import time import time
try:
import tomllib
except:
import tomli as tomllib
import asyncio import asyncio
from datetime import datetime from datetime import datetime
import logging import logging
@ -2072,18 +2077,13 @@ class Slixfeed(slixmpp.ClientXMPP):
ftype='list-single', ftype='list-single',
label='About', label='About',
required=True) required=True)
options.addOption('Slixfeed', 'about') config_dir = config.get_default_config_directory()
options.addOption('RSS Task Force', 'rtf') with open(config_dir + '/' + 'information.toml', mode="rb") as information:
# options.addOption('Manual', 'manual') entries = tomllib.load(information)
options.addOption('Tips', 'tips') for entry in entries:
options.addOption('Services for syndication', 'services') label = entries[entry][0]['title']
options.addOption('Software for syndication', 'software') options.addOption(label, entry)
options.addOption('Terms and conditions', 'terms') # options.addOption('Tips', 'tips')
options.addOption('Privacy policy', 'policy')
options.addOption('License', 'license')
options.addOption('Authors', 'author')
options.addOption('Translators', 'translators')
options.addOption('Thanks', 'thanks')
session['payload'] = form session['payload'] = form
session['next'] = self._handle_about_result session['next'] = self._handle_about_result
session['has_next'] = True session['has_next'] = True
@ -2095,71 +2095,49 @@ class Slixfeed(slixmpp.ClientXMPP):
function_name = sys._getframe().f_code.co_name function_name = sys._getframe().f_code.co_name
logger.debug('{}: jid_full: {}' logger.debug('{}: jid_full: {}'
.format(function_name, jid_full)) .format(function_name, jid_full))
match payload['values']['option']: config_dir = config.get_default_config_directory()
case 'about': with open(config_dir + '/' + 'information.toml', mode="rb") as information:
title = 'About' entries = tomllib.load(information)
subtitle = 'Slixfeed {}\n\n'.format(__version__) entry_key = payload['values']['option']
content = action.manual('information.toml', 'about') # case 'terms':
content += ['\nslixmpp\n'] # title = 'Policies'
content += action.manual('information.toml', 'slixmpp') # subtitle = 'Terms and Conditions'
content += ['\nSleekXMPP\n'] # content = action.manual('information.toml', 'terms')
content += action.manual('information.toml', 'sleekxmpp') # case 'tips':
content += ['\nXMPP\n'] # # Tips and tricks you might have not known about Slixfeed and XMPP!
content += action.manual('information.toml', 'xmpp') # title = 'Help'
case 'rtf': # subtitle = 'Tips & Tricks'
title = 'About' # content = 'This page is not yet available.'
subtitle = 'RSS Task Force' # case 'translators':
content = action.manual('information.toml', 'rtf') # title = 'Translators'
case 'author': # subtitle = 'From all across the world'
title = 'Authors' # content = action.manual('information.toml', 'translators')
subtitle = 'The People Who Made This To Happen' # title = entry_key.capitalize()
content = action.manual('information.toml', 'authors') # form = self['xep_0004'].make_form('result', title)
# case 'manual': for entry in entries[entry_key]:
# title = 'Manual' if 'title' in entry:
# subtitle = 'Slixfeed Manual' title = entry['title']
# content = action.manual('information.toml', 'manual') form = self['xep_0004'].make_form('result', title)
case 'license': subtitle = entry['subtitle']
title = 'License' form['instructions'] = subtitle
subtitle = 'Slixfeed Software License' continue
content = action.manual('information.toml', 'license') for e_key in entry:
case 'policy': e_val = entry[e_key]
title = 'Policies' e_key = e_key.capitalize()
subtitle = 'Privacy Policy' # form.add_field(ftype='fixed',
content = action.manual('information.toml', 'privacy') # value=e_val)
case 'services': print(type(e_val))
title = 'Services' if e_key == 'Name':
subtitle = ('Below are online services that extend the ' form.add_field(ftype='fixed',
'syndication experience by means of bookmarking ' value=e_val)
'and multimedia, and also enhance it by restoring ' continue
'access to news web feeds.') if isinstance(e_val, list):
content = action.manual('information.toml', 'services') form_type = 'text-multi'
case 'software': else:
title = 'Software' form_type = 'text-single'
subtitle = ('Take back control of your news. With free, high-' form.add_field(label=e_key,
'quality, software for your desktop, home and ' ftype=form_type,
'mobile devices.') value=e_val)
content = action.manual('information.toml', 'software')
case 'terms':
title = 'Policies'
subtitle = 'Terms and Conditions'
content = action.manual('information.toml', 'terms')
case 'thanks':
title = 'Thanks'
subtitle = 'We are XMPP'
content = action.manual('information.toml', 'thanks')
case 'tips':
# Tips and tricks you might have not known about Slixfeed and XMPP!
title = 'Help'
subtitle = 'Tips & Tricks'
content = 'This page is not yet available.'
case 'translators':
title = 'Translators'
subtitle = 'From all across the world'
content = action.manual('information.toml', 'translators')
form = self['xep_0004'].make_form('result', title)
form['instructions'] = subtitle
form.add_field(ftype="text-multi",
value=content)
# Gajim displays all form['instructions'] on top # Gajim displays all form['instructions'] on top
# Psi ignore the latter form['instructions'] # Psi ignore the latter form['instructions']
# form['instructions'] = 'YOU!\n🫵\n- Join us -' # form['instructions'] = 'YOU!\n🫵\n- Join us -'
@ -2192,7 +2170,6 @@ class Slixfeed(slixmpp.ClientXMPP):
logger.debug('{}: jid_full: {}' logger.debug('{}: jid_full: {}'
.format(function_name, jid_full)) .format(function_name, jid_full))
import tomllib
config_dir = config.get_default_config_directory() config_dir = config.get_default_config_directory()
with open(config_dir + '/' + 'commands.toml', mode="rb") as commands: with open(config_dir + '/' + 'commands.toml', mode="rb") as commands:
cmds = tomllib.load(commands) cmds = tomllib.load(commands)

View file

@ -333,7 +333,7 @@ class XmppCommand:
options.addOption('All news', 'all') options.addOption('All news', 'all')
# options.addOption('News by subscription', 'feed') # options.addOption('News by subscription', 'feed')
# options.addOption('News by tag', 'tag') # options.addOption('News by tag', 'tag')
options.addOption('Rejected news', 'rejected') options.addOption('Rejected news', 'reject')
options.addOption('Unread news', 'unread') options.addOption('Unread news', 'unread')
session['allow_prev'] = False # Cheogram changes style if that button - which should not be on this form - is present session['allow_prev'] = False # Cheogram changes style if that button - which should not be on this form - is present
session['has_next'] = True session['has_next'] = True
@ -354,14 +354,20 @@ class XmppCommand:
num = 100 num = 100
match payload['values']['action']: match payload['values']['action']:
case 'all': case 'all':
results = sqlite.get_entries(db_file, num) # FIXME results = sqlite.get_entries(db_file, num)
case 'rejected': subtitle = 'Recent {} updates'.format(num)
results = sqlite.get_entries_rejected(db_file, num) # FIXME message = 'There are no news'
case 'reject':
results = sqlite.get_entries_rejected(db_file, num)
subtitle = 'Recent {} updates (rejected)'.format(num)
message = 'There are no rejected news'
case 'unread': case 'unread':
results = sqlite.get_unread_entries(db_file, num) results = sqlite.get_unread_entries(db_file, num)
subtitle = 'Recent {} updates (unread)'.format(num)
message = 'There are no unread news.'
if results: if results:
form = self['xep_0004'].make_form('form', 'Updates') form = self['xep_0004'].make_form('form', 'Updates')
form['instructions'] = 'Recent {} updates'.format(num) form['instructions'] = subtitle
options = form.add_field(var='update', options = form.add_field(var='update',
ftype='list-single', ftype='list-single',
label='News', label='News',
@ -377,8 +383,13 @@ class XmppCommand:
session['payload'] = form session['payload'] = form
session['prev'] = None # Cheogram works as expected with 'allow_prev' set to False Just in case session['prev'] = None # Cheogram works as expected with 'allow_prev' set to False Just in case
else: else:
text_info = 'There are no unread news.' text_info = message
session['allow_prev'] = True
session['has_next'] = False
session['next'] = None
session['notes'] = [['info', text_info]] session['notes'] = [['info', text_info]]
session['payload'] = None
session['prev'] = self._handle_recent
return session return session
@ -520,7 +531,7 @@ class XmppCommand:
error_count = 0 error_count = 0
exist_count = 0 exist_count = 0
for url in urls: for url in urls:
result = await action.add_feed(db_file, url) result = await action.add_feed(self, jid_bare, db_file, url)
if result['error']: if result['error']:
error_count += 1 error_count += 1
elif result['exist']: elif result['exist']:
@ -544,7 +555,7 @@ class XmppCommand:
else: else:
if isinstance(url, list): if isinstance(url, list):
url = url[0] url = url[0]
result = await action.add_feed(db_file, url) result = await action.add_feed(self, jid_bare, db_file, url)
if isinstance(result, list): if isinstance(result, list):
results = result results = result
form = self['xep_0004'].make_form('form', 'Subscriptions') form = self['xep_0004'].make_form('form', 'Subscriptions')
@ -1435,18 +1446,13 @@ class XmppCommand:
ftype='list-single', ftype='list-single',
label='About', label='About',
required=True) required=True)
options.addOption('Slixfeed', 'about') config_dir = config.get_default_config_directory()
options.addOption('RSS Task Force', 'rtf') with open(config_dir + '/' + 'information.toml', mode="rb") as information:
# options.addOption('Manual', 'manual') entries = tomllib.load(information)
options.addOption('Tips', 'tips') for entry in entries:
options.addOption('Services for syndication', 'services') label = entries[entry][0]['title']
options.addOption('Software for syndication', 'software') options.addOption(label, entry)
options.addOption('Terms and conditions', 'terms') # options.addOption('Tips', 'tips')
options.addOption('Privacy policy', 'policy')
options.addOption('License', 'license')
options.addOption('Authors', 'author')
options.addOption('Translators', 'translators')
options.addOption('Thanks', 'thanks')
session['payload'] = form session['payload'] = form
session['next'] = self._handle_about_result session['next'] = self._handle_about_result
session['has_next'] = True session['has_next'] = True
@ -1458,71 +1464,49 @@ class XmppCommand:
function_name = sys._getframe().f_code.co_name function_name = sys._getframe().f_code.co_name
logger.debug('{}: jid_full: {}' logger.debug('{}: jid_full: {}'
.format(function_name, jid_full)) .format(function_name, jid_full))
match payload['values']['option']: config_dir = config.get_default_config_directory()
case 'about': with open(config_dir + '/' + 'information.toml', mode="rb") as information:
title = 'About' entries = tomllib.load(information)
subtitle = 'Slixfeed {}\n\n'.format(__version__) entry_key = payload['values']['option']
content = action.manual('information.toml', 'about') # case 'terms':
content += ['\nslixmpp\n'] # title = 'Policies'
content += action.manual('information.toml', 'slixmpp') # subtitle = 'Terms and Conditions'
content += ['\nSleekXMPP\n'] # content = action.manual('information.toml', 'terms')
content += action.manual('information.toml', 'sleekxmpp') # case 'tips':
content += ['\nXMPP\n'] # # Tips and tricks you might have not known about Slixfeed and XMPP!
content += action.manual('information.toml', 'xmpp') # title = 'Help'
case 'rtf': # subtitle = 'Tips & Tricks'
title = 'About' # content = 'This page is not yet available.'
subtitle = 'RSS Task Force' # case 'translators':
content = action.manual('information.toml', 'rtf') # title = 'Translators'
case 'author': # subtitle = 'From all across the world'
title = 'Authors' # content = action.manual('information.toml', 'translators')
subtitle = 'The People Who Made This To Happen' # title = entry_key.capitalize()
content = action.manual('information.toml', 'authors') # form = self['xep_0004'].make_form('result', title)
# case 'manual': for entry in entries[entry_key]:
# title = 'Manual' if 'title' in entry:
# subtitle = 'Slixfeed Manual' title = entry['title']
# content = action.manual('information.toml', 'manual') form = self['xep_0004'].make_form('result', title)
case 'license': subtitle = entry['subtitle']
title = 'License' form['instructions'] = subtitle
subtitle = 'Slixfeed Software License' continue
content = action.manual('information.toml', 'license') for e_key in entry:
case 'policy': e_val = entry[e_key]
title = 'Policies' e_key = e_key.capitalize()
subtitle = 'Privacy Policy' # form.add_field(ftype='fixed',
content = action.manual('information.toml', 'privacy') # value=e_val)
case 'services': print(type(e_val))
title = 'Services' if e_key == 'Name':
subtitle = ('Below are online services that extend the ' form.add_field(ftype='fixed',
'syndication experience by means of bookmarking ' value=e_val)
'and multimedia, and also enhance it by restoring ' continue
'access to news web feeds.') if isinstance(e_val, list):
content = action.manual('information.toml', 'services') form_type = 'text-multi'
case 'software': else:
title = 'Software' form_type = 'text-single'
subtitle = ('Take back control of your news. With free, high-' form.add_field(label=e_key,
'quality, software for your desktop, home and ' ftype=form_type,
'mobile devices.') value=e_val)
content = action.manual('information.toml', 'software')
case 'terms':
title = 'Policies'
subtitle = 'Terms and Conditions'
content = action.manual('information.toml', 'terms')
case 'thanks':
title = 'Thanks'
subtitle = 'We are XMPP'
content = action.manual('information.toml', 'thanks')
case 'tips':
# Tips and tricks you might have not known about Slixfeed and XMPP!
title = 'Help'
subtitle = 'Tips & Tricks'
content = 'This page is not yet available.'
case 'translators':
title = 'Translators'
subtitle = 'From all across the world'
content = action.manual('information.toml', 'translators')
form = self['xep_0004'].make_form('result', title)
form['instructions'] = subtitle
form.add_field(ftype="text-multi",
value=content)
# Gajim displays all form['instructions'] on top # Gajim displays all form['instructions'] on top
# Psi ignore the latter form['instructions'] # Psi ignore the latter form['instructions']
# form['instructions'] = 'YOU!\n🫵\n- Join us -' # form['instructions'] = 'YOU!\n🫵\n- Join us -'
@ -1555,7 +1539,6 @@ class XmppCommand:
logger.debug('{}: jid_full: {}' logger.debug('{}: jid_full: {}'
.format(function_name, jid_full)) .format(function_name, jid_full))
import tomllib
config_dir = config.get_default_config_directory() config_dir = config.get_default_config_directory()
with open(config_dir + '/' + 'commands.toml', mode="rb") as commands: with open(config_dir + '/' + 'commands.toml', mode="rb") as commands:
cmds = tomllib.load(commands) cmds = tomllib.load(commands)
@ -2127,7 +2110,6 @@ class XmppCommand:
i += 1 i += 1
value = self.settings[jid_bare]['quantum'] or self.settings['default']['quantum'] value = self.settings[jid_bare]['quantum'] or self.settings['default']['quantum']
value = str(value) value = str(value)
value = str(value)
options = form.add_field(var='quantum', options = form.add_field(var='quantum',
ftype='list-single', ftype='list-single',
label='Amount', label='Amount',
@ -2142,7 +2124,6 @@ class XmppCommand:
i += 1 i += 1
value = self.settings[jid_bare]['archive'] or self.settings['default']['archive'] value = self.settings[jid_bare]['archive'] or self.settings['default']['archive']
value = str(value) value = str(value)
value = str(value)
options = form.add_field(var='archive', options = form.add_field(var='archive',
ftype='list-single', ftype='list-single',
label='Archive', label='Archive',
@ -2170,7 +2151,7 @@ class XmppCommand:
jid_full = str(session['from']) jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name function_name = sys._getframe().f_code.co_name
logger.debug('{}: jid_full: {}' logger.debug('{}: jid_full: {}'
.format(function_name, jid_full)) .format(function_name, jid_full))
jid_bare = session['from'].bare jid_bare = session['from'].bare
form = payload form = payload
jid_file = jid_bare jid_file = jid_bare
@ -2183,14 +2164,23 @@ class XmppCommand:
key = value key = value
val = values[value] val = values[value]
if key == 'interval': if key in ('enabled', 'media', 'old'):
if val == True:
val = 1
elif val == False:
val = 0
if key in ('archive', 'interval', 'quantum'):
val = int(val) val = int(val)
if key == 'interval':
if val < 1: val = 1 if val < 1: val = 1
val = val * 60 val = val * 60
is_enabled = self.settings[jid_bare]['enabled'] or self.settings['default']['enabled'] is_enabled = self.settings[jid_bare]['enabled'] or self.settings['default']['enabled']
if (key == 'enabled' and val == 1 and if (key == 'enabled' and
val == 1 and
str(is_enabled) == 0): str(is_enabled) == 0):
logger.info('Slixfeed has been enabled for {}'.format(jid_bare)) logger.info('Slixfeed has been enabled for {}'.format(jid_bare))
status_type = 'available' status_type = 'available'
@ -2201,7 +2191,8 @@ class XmppCommand:
key_list = ['check', 'status', 'interval'] key_list = ['check', 'status', 'interval']
await task.start_tasks_xmpp(self, jid_bare, key_list) await task.start_tasks_xmpp(self, jid_bare, key_list)
if (key == 'enabled' and val == 0 and if (key == 'enabled' and
val == 0 and
str(is_enabled) == 1): str(is_enabled) == 1):
logger.info('Slixfeed has been disabled for {}'.format(jid_bare)) logger.info('Slixfeed has been disabled for {}'.format(jid_bare))
key_list = ['interval', 'status'] key_list = ['interval', 'status']
@ -2211,10 +2202,8 @@ class XmppCommand:
XmppPresence.send(self, jid_bare, status_message, XmppPresence.send(self, jid_bare, status_message,
status_type=status_type) status_type=status_type)
# These three ilnes (getting value after setting it) might be removed await Config.set_setting_value(self.settings, jid_bare, db_file, key, val)
await config.set_setting_value(db_file, key, val) val = self.settings[jid_bare][key]
val = sqlite.get_setting_value(db_file, key)
val = val[0]
# if key == 'enabled': # if key == 'enabled':
# if str(setting.enabled) == 0: # if str(setting.enabled) == 0:

View file

@ -31,6 +31,7 @@ import slixfeed.task as task
# from lxml import etree # from lxml import etree
import slixfeed.config as config import slixfeed.config as config
from slixfeed.config import Config
from slixfeed.log import Logger from slixfeed.log import Logger
from slixfeed.version import __version__ from slixfeed.version import __version__
from slixfeed.xmpp.connect import XmppConnect from slixfeed.xmpp.connect import XmppConnect
@ -49,6 +50,11 @@ from slixfeed.xmpp.utility import get_chat_type
import sys import sys
import time import time
try:
import tomllib
except:
import tomli as tomllib
import asyncio import asyncio
from datetime import datetime from datetime import datetime
import logging import logging
@ -918,7 +924,7 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
options.addOption('All news', 'all') options.addOption('All news', 'all')
# options.addOption('News by subscription', 'feed') # options.addOption('News by subscription', 'feed')
# options.addOption('News by tag', 'tag') # options.addOption('News by tag', 'tag')
options.addOption('Rejected news', 'rejected') options.addOption('Rejected news', 'reject')
options.addOption('Unread news', 'unread') options.addOption('Unread news', 'unread')
session['allow_prev'] = False # Cheogram changes style if that button - which should not be on this form - is present session['allow_prev'] = False # Cheogram changes style if that button - which should not be on this form - is present
session['has_next'] = True session['has_next'] = True
@ -939,14 +945,20 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
num = 100 num = 100
match payload['values']['action']: match payload['values']['action']:
case 'all': case 'all':
results = sqlite.get_entries(db_file, num) # FIXME results = sqlite.get_entries(db_file, num)
case 'rejected': subtitle = 'Recent {} updates'.format(num)
results = sqlite.get_entries_rejected(db_file, num) # FIXME message = 'There are no news'
case 'reject':
results = sqlite.get_entries_rejected(db_file, num)
subtitle = 'Recent {} updates (rejected)'.format(num)
message = 'There are no rejected news'
case 'unread': case 'unread':
results = sqlite.get_unread_entries(db_file, num) results = sqlite.get_unread_entries(db_file, num)
subtitle = 'Recent {} updates (unread)'.format(num)
message = 'There are no unread news.'
if results: if results:
form = self['xep_0004'].make_form('form', 'Updates') form = self['xep_0004'].make_form('form', 'Updates')
form['instructions'] = 'Recent {} updates'.format(num) form['instructions'] = subtitle
options = form.add_field(var='update', options = form.add_field(var='update',
ftype='list-single', ftype='list-single',
label='News', label='News',
@ -962,8 +974,13 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
session['payload'] = form session['payload'] = form
session['prev'] = None # Cheogram works as expected with 'allow_prev' set to False Just in case session['prev'] = None # Cheogram works as expected with 'allow_prev' set to False Just in case
else: else:
text_info = 'There are no unread news.' text_info = message
session['allow_prev'] = True
session['has_next'] = False
session['next'] = None
session['notes'] = [['info', text_info]] session['notes'] = [['info', text_info]]
session['payload'] = None
session['prev'] = self._handle_recent
return session return session
@ -2020,18 +2037,13 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
ftype='list-single', ftype='list-single',
label='About', label='About',
required=True) required=True)
options.addOption('Slixfeed', 'about') config_dir = config.get_default_config_directory()
options.addOption('RSS Task Force', 'rtf') with open(config_dir + '/' + 'information.toml', mode="rb") as information:
# options.addOption('Manual', 'manual') entries = tomllib.load(information)
options.addOption('Tips', 'tips') for entry in entries:
options.addOption('Services for syndication', 'services') label = entries[entry][0]['title']
options.addOption('Software for syndication', 'software') options.addOption(label, entry)
options.addOption('Terms and conditions', 'terms') # options.addOption('Tips', 'tips')
options.addOption('Privacy policy', 'policy')
options.addOption('License', 'license')
options.addOption('Authors', 'author')
options.addOption('Translators', 'translators')
options.addOption('Thanks', 'thanks')
session['payload'] = form session['payload'] = form
session['next'] = self._handle_about_result session['next'] = self._handle_about_result
session['has_next'] = True session['has_next'] = True
@ -2043,71 +2055,49 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
function_name = sys._getframe().f_code.co_name function_name = sys._getframe().f_code.co_name
logger.debug('{}: jid_full: {}' logger.debug('{}: jid_full: {}'
.format(function_name, jid_full)) .format(function_name, jid_full))
match payload['values']['option']: config_dir = config.get_default_config_directory()
case 'about': with open(config_dir + '/' + 'information.toml', mode="rb") as information:
title = 'About' entries = tomllib.load(information)
subtitle = 'Slixfeed {}\n\n'.format(__version__) entry_key = payload['values']['option']
content = action.manual('information.toml', 'about') # case 'terms':
content += ['\nslixmpp\n'] # title = 'Policies'
content += action.manual('information.toml', 'slixmpp') # subtitle = 'Terms and Conditions'
content += ['\nSleekXMPP\n'] # content = action.manual('information.toml', 'terms')
content += action.manual('information.toml', 'sleekxmpp') # case 'tips':
content += ['\nXMPP\n'] # # Tips and tricks you might have not known about Slixfeed and XMPP!
content += action.manual('information.toml', 'xmpp') # title = 'Help'
case 'rtf': # subtitle = 'Tips & Tricks'
title = 'About' # content = 'This page is not yet available.'
subtitle = 'RSS Task Force' # case 'translators':
content = action.manual('information.toml', 'rtf') # title = 'Translators'
case 'author': # subtitle = 'From all across the world'
title = 'Authors' # content = action.manual('information.toml', 'translators')
subtitle = 'The People Who Made This To Happen' # title = entry_key.capitalize()
content = action.manual('information.toml', 'authors') # form = self['xep_0004'].make_form('result', title)
# case 'manual': for entry in entries[entry_key]:
# title = 'Manual' if 'title' in entry:
# subtitle = 'Slixfeed Manual' title = entry['title']
# content = action.manual('information.toml', 'manual') form = self['xep_0004'].make_form('result', title)
case 'license': subtitle = entry['subtitle']
title = 'License' form['instructions'] = subtitle
subtitle = 'Slixfeed Software License' continue
content = action.manual('information.toml', 'license') for e_key in entry:
case 'policy': e_val = entry[e_key]
title = 'Policies' e_key = e_key.capitalize()
subtitle = 'Privacy Policy' # form.add_field(ftype='fixed',
content = action.manual('information.toml', 'privacy') # value=e_val)
case 'services': print(type(e_val))
title = 'Services' if e_key == 'Name':
subtitle = ('Below are online services that extend the ' form.add_field(ftype='fixed',
'syndication experience by means of bookmarking ' value=e_val)
'and multimedia, and also enhance it by restoring ' continue
'access to news web feeds.') if isinstance(e_val, list):
content = action.manual('information.toml', 'services') form_type = 'text-multi'
case 'software': else:
title = 'Software' form_type = 'text-single'
subtitle = ('Take back control of your news. With free, high-' form.add_field(label=e_key,
'quality, software for your desktop, home and ' ftype=form_type,
'mobile devices.') value=e_val)
content = action.manual('information.toml', 'software')
case 'terms':
title = 'Policies'
subtitle = 'Terms and Conditions'
content = action.manual('information.toml', 'terms')
case 'thanks':
title = 'Thanks'
subtitle = 'We are XMPP'
content = action.manual('information.toml', 'thanks')
case 'tips':
# Tips and tricks you might have not known about Slixfeed and XMPP!
title = 'Help'
subtitle = 'Tips & Tricks'
content = 'This page is not yet available.'
case 'translators':
title = 'Translators'
subtitle = 'From all across the world'
content = action.manual('information.toml', 'translators')
form = self['xep_0004'].make_form('result', title)
form['instructions'] = subtitle
form.add_field(ftype="text-multi",
value=content)
# Gajim displays all form['instructions'] on top # Gajim displays all form['instructions'] on top
# Psi ignore the latter form['instructions'] # Psi ignore the latter form['instructions']
# form['instructions'] = 'YOU!\n🫵\n- Join us -' # form['instructions'] = 'YOU!\n🫵\n- Join us -'
@ -2140,7 +2130,6 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
logger.debug('{}: jid_full: {}' logger.debug('{}: jid_full: {}'
.format(function_name, jid_full)) .format(function_name, jid_full))
import tomllib
config_dir = config.get_default_config_directory() config_dir = config.get_default_config_directory()
with open(config_dir + '/' + 'commands.toml', mode="rb") as commands: with open(config_dir + '/' + 'commands.toml', mode="rb") as commands:
cmds = tomllib.load(commands) cmds = tomllib.load(commands)

View file

@ -307,8 +307,10 @@ async def message(self, message):
await sqlite.insert_feed(db_file, url, title) await sqlite.insert_feed(db_file, url, title)
await action.scan(self, jid_bare, db_file, url) await action.scan(self, jid_bare, db_file, url)
if jid_bare not in self.settings: if jid_bare not in self.settings:
Config.add_settings_jid(self.settings, jid_bare, db_file) Config.add_settings_jid(self.settings, jid_bare,
old = self.settings[jid_bare]['old'] or self.settings['default']['old'] db_file)
old = Config.get_setting_value(self.settings, jid_bare,
'old')
if old: if old:
# task.clean_tasks_xmpp(self, jid_bare, ['status']) # task.clean_tasks_xmpp(self, jid_bare, ['status'])
# await send_status(jid) # await send_status(jid)
@ -382,14 +384,18 @@ async def message(self, message):
val = message_text[8:] val = message_text[8:]
if val: if val:
try: try:
if int(val) > 500: val_new = int(val)
if val_new > 500:
response = 'Value may not be greater than 500.' response = 'Value may not be greater than 500.'
else: else:
val_old = Config.get_setting_value(
self.settings, jid_bare, key)
db_file = config.get_pathname_to_database(jid_file) db_file = config.get_pathname_to_database(jid_file)
await Config.set_setting_value(self.settings, jid_bare, db_file, key, val) await Config.set_setting_value(
self.settings, jid_bare, db_file, key, val_new)
response = ('Maximum archived items has ' response = ('Maximum archived items has '
'been set to {}.' 'been set to {} (was: {}).'
.format(val)) .format(val_new, val_old))
except: except:
response = ('No action has been taken.' response = ('No action has been taken.'
'\n' '\n'
@ -581,12 +587,11 @@ async def message(self, message):
if error: if error:
response = ('> {}\n' response = ('> {}\n'
'Failed to export {}. ' 'Failed to export {}. '
'Reason: {}'.format(url, 'Reason: {}'.format(
ext.upper(), url, ext.upper(), error))
error))
else: else:
url = await XmppUpload.start(self, jid_bare, url = await XmppUpload.start(
filename) self, jid_bare, filename)
chat_type = await get_chat_type(self, chat_type = await get_chat_type(self,
jid_bare) jid_bare)
XmppMessage.send_oob(self, jid_bare, url, XmppMessage.send_oob(self, jid_bare, url,
@ -661,8 +666,8 @@ async def message(self, message):
result['name'], result['name'],
result['index'])) result['index']))
elif result['error']: elif result['error']:
response = ('> {}\nFailed to find subscriptions. Reason: {}' response = ('> {}\nFailed to find subscriptions. '
.format(url, result['code'])) 'Reason: {}'.format(url, result['code']))
else: else:
response = ('> {}\nNews source "{}" has been ' response = ('> {}\nNews source "{}" has been '
'added to subscription list.' 'added to subscription list.'
@ -702,15 +707,17 @@ async def message(self, message):
val = message_text[9:] val = message_text[9:]
if val: if val:
try: try:
val = int(val) val_new = int(val)
val_old = Config.get_setting_value(self.settings, jid_bare, key)
db_file = config.get_pathname_to_database(jid_file) db_file = config.get_pathname_to_database(jid_file)
await Config.set_setting_value(self.settings, jid_bare, db_file, key, val) await Config.set_setting_value(
self.settings, jid_bare, db_file, key, val_new)
# NOTE Perhaps this should be replaced by functions # NOTE Perhaps this should be replaced by functions
# clean and start # clean and start
task.refresh_task(self, jid_bare, task.task_send, key, task.refresh_task(self, jid_bare, task.task_send, key,
val) val_new)
response = ('Updates will be sent every {} minutes.' response = ('Updates will be sent every {} minutes '
.format(val)) '(was: {}).'.format(val_new, val_old))
except: except:
response = ('No action has been taken.' response = ('No action has been taken.'
'\n' '\n'
@ -736,15 +743,19 @@ async def message(self, message):
val = message_text[7:] val = message_text[7:]
if val: if val:
try: try:
val = int(val) val_new = int(val)
val_old = Config.get_setting_value(
self.settings, jid_bare, key)
db_file = config.get_pathname_to_database(jid_file) db_file = config.get_pathname_to_database(jid_file)
await Config.set_setting_value(self.settings, jid_bare, db_file, key, val) await Config.set_setting_value(
if val == 0: # if not val: self.settings, jid_bare, db_file, key, val_new)
response = 'Summary length limit is disabled.' if val_new == 0: # if not val:
response = ('Summary length limit is disabled '
'(was: {}).'.format(val_old))
else: else:
response = ('Summary maximum length ' response = ('Summary maximum length is set to '
'is set to {} characters.' '{} characters (was: {}).'
.format(val)) .format(val_new, val_old))
except: except:
response = ('No action has been taken.' response = ('No action has been taken.'
'\n' '\n'
@ -782,21 +793,24 @@ async def message(self, message):
db_file = config.get_pathname_to_database(jid_file) db_file = config.get_pathname_to_database(jid_file)
key = 'media' key = 'media'
val = 0 val = 0
await Config.set_setting_value(self.settings, jid_bare, db_file, key, val) await Config.set_setting_value(
self.settings, jid_bare, db_file, key, val)
response = 'Media is disabled.' response = 'Media is disabled.'
XmppMessage.send_reply(self, message, response) XmppMessage.send_reply(self, message, response)
case 'media on': case 'media on':
db_file = config.get_pathname_to_database(jid_file) db_file = config.get_pathname_to_database(jid_file)
key = 'media' key = 'media'
val = 1 val = 1
await Config.set_setting_value(self.settings, jid_bare, db_file, key, val) await Config.set_setting_value(self.settings, jid_bare,
db_file, key, val)
response = 'Media is enabled.' response = 'Media is enabled.'
XmppMessage.send_reply(self, message, response) XmppMessage.send_reply(self, message, response)
case 'new': case 'new':
db_file = config.get_pathname_to_database(jid_file) db_file = config.get_pathname_to_database(jid_file)
key = 'old' key = 'old'
val = 0 val = 0
await Config.set_setting_value(self.settings, jid_bare, db_file, key, val) await Config.set_setting_value(self.settings, jid_bare,
db_file, key, val)
response = 'Only new items of newly added feeds be delivered.' response = 'Only new items of newly added feeds be delivered.'
XmppMessage.send_reply(self, message, response) XmppMessage.send_reply(self, message, response)
case _ if message_lowercase.startswith('next'): case _ if message_lowercase.startswith('next'):
@ -811,7 +825,8 @@ async def message(self, message):
db_file = config.get_pathname_to_database(jid_file) db_file = config.get_pathname_to_database(jid_file)
key = 'old' key = 'old'
val = 1 val = 1
await Config.set_setting_value(self.settings, jid_bare, db_file, key, val) await Config.set_setting_value(self.settings, jid_bare,
db_file, key, val)
response = 'All items of newly added feeds be delivered.' response = 'All items of newly added feeds be delivered.'
XmppMessage.send_reply(self, message, response) XmppMessage.send_reply(self, message, response)
case _ if message_lowercase.startswith('quantum'): case _ if message_lowercase.startswith('quantum'):
@ -819,14 +834,17 @@ async def message(self, message):
val = message_text[8:] val = message_text[8:]
if val: if val:
try: try:
val = int(val) val_new = int(val)
val_old = Config.get_setting_value(self.settings,
jid_bare, key)
# response = ( # response = (
# 'Every update will contain {} news items.' # 'Every update will contain {} news items.'
# ).format(response) # ).format(response)
db_file = config.get_pathname_to_database(jid_file) db_file = config.get_pathname_to_database(jid_file)
await Config.set_setting_value(self.settings, jid_bare, db_file, key, val) await Config.set_setting_value(self.settings, jid_bare,
response = ('Next update will contain {} news items.' db_file, key, val_new)
.format(val)) response = ('Next update will contain {} news items '
'(was: {}).'.format(val_new, val_old))
except: except:
response = ('No action has been taken.' response = ('No action has been taken.'
'\n' '\n'
@ -849,8 +867,8 @@ async def message(self, message):
key_list = ['status'] key_list = ['status']
task.clean_tasks_xmpp(self, jid_bare, key_list) task.clean_tasks_xmpp(self, jid_bare, key_list)
status_type = 'dnd' status_type = 'dnd'
status_message = ('📫️ Processing request to fetch data from {}' status_message = ('📫️ Processing request to fetch data '
.format(url)) 'from {}'.format(url))
XmppPresence.send(self, jid_bare, status_message, XmppPresence.send(self, jid_bare, status_message,
status_type=status_type) status_type=status_type)
if url.startswith('feed:'): if url.startswith('feed:'):
@ -1015,10 +1033,12 @@ async def message(self, message):
key = 'enabled' key = 'enabled'
val = 1 val = 1
db_file = config.get_pathname_to_database(jid_file) db_file = config.get_pathname_to_database(jid_file)
await Config.set_setting_value(self.settings, jid_bare, db_file, key, val) await Config.set_setting_value(self.settings, jid_bare,
db_file, key, val)
status_type = 'available' status_type = 'available'
status_message = '📫️ Welcome back!' status_message = '📫️ Welcome back!'
XmppPresence.send(self, jid_bare, status_message, status_type=status_type) XmppPresence.send(self, jid_bare, status_message,
status_type=status_type)
await asyncio.sleep(5) await asyncio.sleep(5)
key_list = ['check', 'status', 'interval'] key_list = ['check', 'status', 'interval']
await task.start_tasks_xmpp(self, jid_bare, key_list) await task.start_tasks_xmpp(self, jid_bare, key_list)
@ -1064,14 +1084,16 @@ async def message(self, message):
'Input name is identical to the ' 'Input name is identical to the '
'existing name.') 'existing name.')
else: else:
await sqlite.set_feed_title(db_file, feed_id, name) await sqlite.set_feed_title(db_file, feed_id,
name)
response = ('> {}' response = ('> {}'
'\n' '\n'
'Subscription #{} has been renamed to "{}".' 'Subscription #{} has been '
.format(name_old, feed_id, name)) 'renamed to "{}".'.format(
name_old,feed_id, name))
else: else:
response = ('Subscription with Id {} does not exist.' response = ('Subscription with Id {} does not '
.format(feed_id)) 'exist.'.format(feed_id))
except: except:
response = ('No action has been taken.' response = ('No action has been taken.'
'\n' '\n'
@ -1101,7 +1123,8 @@ async def message(self, message):
key = 'enabled' key = 'enabled'
val = 0 val = 0
db_file = config.get_pathname_to_database(jid_file) db_file = config.get_pathname_to_database(jid_file)
await Config.set_setting_value(self.settings, jid_bare, db_file, key, val) await Config.set_setting_value(
self.settings, jid_bare, db_file, key, val)
key_list = ['interval', 'status'] key_list = ['interval', 'status']
task.clean_tasks_xmpp(self, jid_bare, key_list) task.clean_tasks_xmpp(self, jid_bare, key_list)
status_type = 'xa' status_type = 'xa'