epicyon/webapp_frontscreen.py

237 lines
10 KiB
Python
Raw Normal View History

__filename__ = "webapp_frontscreen.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
2024-01-21 19:01:20 +00:00
__version__ = "1.5.0"
__maintainer__ = "Bob Mottram"
2021-09-10 16:14:50 +00:00
__email__ = "bob@libreserver.org"
__status__ = "Production"
2021-06-26 11:27:14 +00:00
__module_group__ = "Timeline"
import os
from flags import is_system_account
2021-12-27 19:05:25 +00:00
from utils import get_domain_from_actor
2021-12-26 14:08:58 +00:00
from utils import get_config_param
2022-02-25 19:12:40 +00:00
from utils import get_account_timezone
2021-12-28 16:50:20 +00:00
from person import person_box_json
2021-12-29 21:55:09 +00:00
from webapp_utils import html_header_with_external_style
from webapp_utils import html_footer
from webapp_utils import get_banner_file
from webapp_utils import html_post_separator
from webapp_utils import header_buttons_front_screen
from webapp_column_left import get_left_column_content
from webapp_column_right import get_right_column_content
from webapp_post import individual_post_as_html
2021-12-29 21:55:09 +00:00
def _html_front_screen_posts(recent_posts_cache: {}, max_recent_posts: int,
translate: {},
base_dir: str, http_prefix: str,
nickname: str, domain: str, port: int,
session, cached_webfingers: {}, person_cache: {},
project_version: str,
yt_replace_domain: str,
twitter_replacement_domain: str,
show_published_date_only: bool,
peertube_instances: [],
allow_local_network_access: bool,
theme_name: str, system_language: str,
max_like_count: int,
signing_priv_key_pem: str, cw_lists: {},
2022-03-24 13:14:41 +00:00
lists_enabled: str,
2022-07-05 14:40:26 +00:00
bold_reading: bool,
dogwhistles: {},
2023-01-13 15:04:48 +00:00
min_images_for_accounts: [],
buy_sites: {},
auto_cw_cache: {}) -> str:
"""Shows posts on the front screen of a news instance
These should only be public blog posts from the features timeline
which is the blog timeline of the news actor
"""
2022-01-03 22:50:01 +00:00
separator_str = html_post_separator(base_dir, None)
profile_str = ''
max_items = 4
ctr = 0
2022-01-03 22:50:01 +00:00
curr_page = 1
box_name = 'tlfeatures'
authorized = True
2022-01-03 22:50:01 +00:00
while ctr < max_items and curr_page < 4:
outbox_feed_path_str = \
'/users/' + nickname + '/' + box_name + \
'?page=' + str(curr_page)
outbox_feed = \
2022-09-08 17:59:19 +00:00
person_box_json({}, base_dir, domain, port,
2022-01-03 22:50:01 +00:00
outbox_feed_path_str,
http_prefix, 10, box_name,
2021-12-28 16:50:20 +00:00
authorized, 0, False, 0)
2022-01-03 22:50:01 +00:00
if not outbox_feed:
break
2022-01-03 22:50:01 +00:00
if len(outbox_feed['orderedItems']) == 0:
break
2022-01-03 22:50:01 +00:00
for item in outbox_feed['orderedItems']:
2024-07-18 19:39:10 +00:00
if item['type'] != 'Create':
continue
timezone = get_account_timezone(base_dir, nickname, domain)
minimize_all_images = False
if nickname in min_images_for_accounts:
minimize_all_images = True
post_str = \
individual_post_as_html(signing_priv_key_pem,
True, recent_posts_cache,
max_recent_posts,
translate, None,
base_dir, session,
cached_webfingers,
person_cache,
nickname, domain, port, item,
None, True, False,
http_prefix,
project_version, 'inbox',
yt_replace_domain,
twitter_replacement_domain,
show_published_date_only,
peertube_instances,
allow_local_network_access,
theme_name, system_language,
max_like_count,
False, False, False,
True, False, False,
cw_lists, lists_enabled,
timezone, False,
bold_reading, dogwhistles,
minimize_all_images, None,
buy_sites, auto_cw_cache)
if post_str:
profile_str += post_str + separator_str
ctr += 1
if ctr >= max_items:
break
2022-01-03 22:50:01 +00:00
curr_page += 1
return profile_str
2021-12-29 21:55:09 +00:00
def html_front_screen(signing_priv_key_pem: str,
rss_icon_at_top: bool,
2022-07-12 19:03:30 +00:00
icons_as_buttons: bool,
2021-12-31 23:50:29 +00:00
default_timeline: str,
2021-12-29 21:55:09 +00:00
recent_posts_cache: {}, max_recent_posts: int,
translate: {}, project_version: str,
base_dir: str, http_prefix: str, authorized: bool,
2024-02-26 11:24:00 +00:00
profile_json: {},
2021-12-29 21:55:09 +00:00
session, cached_webfingers: {}, person_cache: {},
yt_replace_domain: str,
twitter_replacement_domain: str,
show_published_date_only: bool,
newswire: {}, theme: str,
peertube_instances: [],
allow_local_network_access: bool,
2021-12-31 21:18:12 +00:00
access_keys: {},
2021-12-29 21:55:09 +00:00
system_language: str, max_like_count: int,
shared_items_federated_domains: [],
2022-07-05 14:40:26 +00:00
cw_lists: {}, lists_enabled: str,
dogwhistles: {},
2023-01-13 15:04:48 +00:00
min_images_for_accounts: [],
buy_sites: {},
auto_cw_cache: {}) -> str:
"""Show the news instance front screen
"""
2022-03-24 13:14:41 +00:00
bold_reading = False
2021-12-26 10:08:06 +00:00
nickname = profile_json['preferredUsername']
if not nickname:
return ""
2021-12-27 15:41:04 +00:00
if not is_system_account(nickname):
return ""
2021-12-27 19:05:25 +00:00
domain, port = get_domain_from_actor(profile_json['id'])
if not domain:
return ""
2021-12-26 10:00:46 +00:00
domain_full = domain
if port:
2021-12-26 10:00:46 +00:00
domain_full = domain + ':' + str(port)
2022-01-03 22:50:01 +00:00
login_button = header_buttons_front_screen(translate, nickname,
'features', authorized,
icons_as_buttons)
# If this is the news account then show a different banner
2022-01-03 22:50:01 +00:00
banner_file, _ = \
2021-12-29 21:55:09 +00:00
get_banner_file(base_dir, nickname, domain, theme)
2022-01-03 22:50:01 +00:00
profile_header_str = \
2022-03-28 08:47:53 +00:00
'<img loading="lazy" decoding="async" class="timeline-banner" ' + \
2021-12-31 21:18:12 +00:00
'src="/users/' + nickname + '/' + banner_file + '" />\n'
2022-01-03 22:50:01 +00:00
if login_button:
profile_header_str += '<center>' + login_button + '</center>\n'
2022-01-03 22:50:01 +00:00
profile_header_str += \
2021-07-05 20:24:43 +00:00
'<table class="timeline">\n' + \
' <colgroup>\n' + \
' <col span="1" class="column-left">\n' + \
' <col span="1" class="column-center">\n' + \
' <col span="1" class="column-right">\n' + \
' </colgroup>\n' + \
' <tbody>\n' + \
' <tr>\n' + \
2022-05-25 10:17:44 +00:00
' <td valign="top" class="col-left" tabindex="-1">\n'
2022-01-03 22:50:01 +00:00
profile_header_str += \
2021-12-29 21:55:09 +00:00
get_left_column_content(base_dir, 'news', domain_full,
http_prefix, translate,
False, False,
False, None, rss_icon_at_top, True,
2021-12-31 21:18:12 +00:00
True, theme, access_keys,
2021-12-29 21:55:09 +00:00
shared_items_federated_domains)
2022-01-03 22:50:01 +00:00
profile_header_str += \
2021-07-05 20:24:43 +00:00
' </td>\n' + \
2022-05-25 10:17:44 +00:00
' <td valign="top" class="col-center" tabindex="-1">\n'
2022-01-03 22:50:01 +00:00
profile_str = profile_header_str
2021-12-31 21:18:12 +00:00
css_filename = base_dir + '/epicyon-profile.css'
2021-12-25 16:17:53 +00:00
if os.path.isfile(base_dir + '/epicyon.css'):
2021-12-31 21:18:12 +00:00
css_filename = base_dir + '/epicyon.css'
2022-01-03 22:50:01 +00:00
license_str = ''
banner_file, _ = \
2021-12-29 21:55:09 +00:00
get_banner_file(base_dir, nickname, domain, theme)
2022-01-03 22:50:01 +00:00
profile_str += \
2021-12-29 21:55:09 +00:00
_html_front_screen_posts(recent_posts_cache, max_recent_posts,
translate,
base_dir, http_prefix,
nickname, domain, port,
session, cached_webfingers, person_cache,
project_version,
yt_replace_domain,
twitter_replacement_domain,
show_published_date_only,
peertube_instances,
allow_local_network_access,
theme, system_language,
max_like_count,
signing_priv_key_pem,
2022-03-24 13:14:41 +00:00
cw_lists, lists_enabled,
bold_reading, dogwhistles,
2023-01-13 15:04:48 +00:00
min_images_for_accounts,
buy_sites,
auto_cw_cache) + license_str
# Footer which is only used for system accounts
2022-01-03 22:50:01 +00:00
profile_footer_str = ' </td>\n'
2022-05-25 10:13:26 +00:00
profile_footer_str += \
2022-05-25 10:17:44 +00:00
' <td valign="top" class="col-right" tabindex="-1">\n'
2022-01-03 22:50:01 +00:00
profile_footer_str += \
2021-12-29 21:55:09 +00:00
get_right_column_content(base_dir, 'news', domain_full,
2024-02-09 13:52:25 +00:00
translate,
2021-12-29 21:55:09 +00:00
False, False, newswire, False,
False, None, False, False,
False, True, authorized, True, theme,
2021-12-31 23:50:29 +00:00
default_timeline, access_keys)
2022-01-03 22:50:01 +00:00
profile_footer_str += \
2021-07-05 20:24:43 +00:00
' </td>\n' + \
' </tr>\n' + \
' </tbody>\n' + \
'</table>\n'
2022-01-03 22:50:01 +00:00
instance_title = \
2021-12-26 14:08:58 +00:00
get_config_param(base_dir, 'instanceTitle')
2022-01-03 22:50:01 +00:00
profile_str = \
html_header_with_external_style(css_filename, instance_title, None) + \
profile_str + profile_footer_str + html_footer()
return profile_str