epicyon/webapp_frontscreen.py

215 lines
9.3 KiB
Python
Raw Normal View History

__filename__ = "webapp_frontscreen.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
2022-02-03 13:58:20 +00:00
__version__ = "1.3.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
2021-12-27 15:41:04 +00:00
from utils 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
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: {},
lists_enabled: str) -> 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 = \
2021-12-28 16:50:20 +00:00
person_box_json({}, session, 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']:
if item['type'] == 'Create':
2022-01-03 22:50:01 +00:00
post_str = \
2021-12-29 21:55:09 +00:00
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)
2022-01-03 22:50:01 +00:00
if post_str:
profile_str += post_str + separator_str
ctr += 1
2022-01-03 22:50:01 +00:00
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,
css_cache: {}, 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,
profile_json: {}, selected: str,
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-01-03 22:50:01 +00:00
extra_json: {},
page_number: int,
max_items_per_page: int,
2021-12-29 21:55:09 +00:00
cw_lists: {}, lists_enabled: str) -> str:
"""Show the news instance front screen
"""
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 = \
'<img loading="lazy" 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' + \
' <td valign="top" class="col-left">\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' + \
' <td valign="top" class="col-center">\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-01-03 22:50:01 +00:00
cw_lists, lists_enabled) + license_str
# Footer which is only used for system accounts
2022-01-03 22:50:01 +00:00
profile_footer_str = ' </td>\n'
profile_footer_str += ' <td valign="top" class="col-right">\n'
profile_footer_str += \
2021-12-29 21:55:09 +00:00
get_right_column_content(base_dir, 'news', domain_full,
http_prefix, translate,
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