epicyon/webapp_frontscreen.py

214 lines
8.8 KiB
Python
Raw Normal View History

__filename__ = "webapp_frontscreen.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
2021-01-26 10:07:42 +00:00
__version__ = "1.2.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 utils import isSystemAccount
from utils import getDomainFromActor
2021-01-11 19:46:21 +00:00
from utils import getConfigParam
from person import personBoxJson
from webapp_utils import htmlHeaderWithExternalStyle
from webapp_utils import htmlFooter
from webapp_utils import getBannerFile
from webapp_utils import htmlPostSeparator
2020-11-28 10:19:59 +00:00
from webapp_utils import headerButtonsFrontScreen
from webapp_column_left import getLeftColumnContent
from webapp_column_right import getRightColumnContent
from webapp_post import individualPostAsHtml
def _htmlFrontScreenPosts(recentPostsCache: {}, maxRecentPosts: int,
translate: {},
2021-12-25 17:09:22 +00:00
base_dir: str, http_prefix: str,
nickname: str, domain: str, port: int,
session, cachedWebfingers: {}, personCache: {},
projectVersion: str,
2021-12-25 17:15:52 +00:00
yt_replace_domain: str,
2021-09-18 17:08:14 +00:00
twitterReplacementDomain: str,
2020-12-23 23:59:49 +00:00
showPublishedDateOnly: bool,
peertubeInstances: [],
2021-03-09 19:52:10 +00:00
allowLocalNetworkAccess: bool,
themeName: str, systemLanguage: str,
2021-12-25 18:23:12 +00:00
max_like_count: int,
signingPrivateKeyPem: str, CWlists: {},
2021-12-25 18:12:13 +00:00
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
"""
2021-12-25 16:17:53 +00:00
separatorStr = htmlPostSeparator(base_dir, None)
profileStr = ''
maxItems = 4
ctr = 0
currPage = 1
boxName = 'tlfeatures'
authorized = True
while ctr < maxItems and currPage < 4:
outboxFeedPathStr = \
'/users/' + nickname + '/' + boxName + \
'?page=' + str(currPage)
outboxFeed = \
2021-12-25 16:17:53 +00:00
personBoxJson({}, session, base_dir, domain, port,
outboxFeedPathStr,
2021-12-25 17:09:22 +00:00
http_prefix, 10, boxName,
authorized, 0, False, 0)
if not outboxFeed:
break
if len(outboxFeed['orderedItems']) == 0:
break
for item in outboxFeed['orderedItems']:
if item['type'] == 'Create':
postStr = \
individualPostAsHtml(signingPrivateKeyPem,
True, recentPostsCache,
maxRecentPosts,
2020-12-09 13:31:54 +00:00
translate, None,
2021-12-25 16:17:53 +00:00
base_dir, session,
cachedWebfingers,
personCache,
nickname, domain, port, item,
None, True, False,
2021-12-25 17:09:22 +00:00
http_prefix, projectVersion, 'inbox',
2021-12-25 17:15:52 +00:00
yt_replace_domain,
2021-09-18 17:08:14 +00:00
twitterReplacementDomain,
showPublishedDateOnly,
2020-12-23 23:59:49 +00:00
peertubeInstances,
allowLocalNetworkAccess,
themeName, systemLanguage,
2021-12-25 18:23:12 +00:00
max_like_count,
False, False, False,
2021-10-21 13:08:21 +00:00
True, False, False,
2021-12-25 18:12:13 +00:00
CWlists, lists_enabled)
if postStr:
profileStr += postStr + separatorStr
ctr += 1
if ctr >= maxItems:
break
currPage += 1
return profileStr
def htmlFrontScreen(signingPrivateKeyPem: str,
rssIconAtTop: bool,
cssCache: {}, iconsAsButtons: bool,
defaultTimeline: str,
recentPostsCache: {}, maxRecentPosts: int,
translate: {}, projectVersion: str,
2021-12-25 17:09:22 +00:00
base_dir: str, http_prefix: str, authorized: bool,
profileJson: {}, selected: str,
session, cachedWebfingers: {}, personCache: {},
2021-12-25 17:15:52 +00:00
yt_replace_domain: str,
2021-09-18 17:08:14 +00:00
twitterReplacementDomain: str,
showPublishedDateOnly: bool,
2020-12-23 23:59:49 +00:00
newswire: {}, theme: str,
peertubeInstances: [],
allowLocalNetworkAccess: bool,
2021-04-23 16:29:03 +00:00
accessKeys: {},
2021-12-25 18:23:12 +00:00
systemLanguage: str, max_like_count: int,
2021-12-25 18:05:01 +00:00
shared_items_federated_domains: [],
2021-10-21 13:08:21 +00:00
extraJson: {},
pageNumber: int,
maxItemsPerPage: int,
2021-12-25 18:12:13 +00:00
CWlists: {}, lists_enabled: str) -> str:
"""Show the news instance front screen
"""
nickname = profileJson['preferredUsername']
if not nickname:
return ""
if not isSystemAccount(nickname):
return ""
domain, port = getDomainFromActor(profileJson['id'])
if not domain:
return ""
domainFull = domain
if port:
domainFull = domain + ':' + str(port)
loginButton = headerButtonsFrontScreen(translate, nickname,
'features', authorized,
2020-12-09 13:31:54 +00:00
iconsAsButtons)
# If this is the news account then show a different banner
2020-12-20 18:16:53 +00:00
bannerFile, bannerFilename = \
2021-12-25 16:17:53 +00:00
getBannerFile(base_dir, nickname, domain, theme)
profileHeaderStr = \
'<img loading="lazy" class="timeline-banner" ' + \
'src="/users/' + nickname + '/' + bannerFile + '" />\n'
if loginButton:
profileHeaderStr += '<center>' + loginButton + '</center>\n'
2021-07-05 20:24:43 +00:00
profileHeaderStr += \
'<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'
profileHeaderStr += \
2021-12-25 16:17:53 +00:00
getLeftColumnContent(base_dir, 'news', domainFull,
2021-12-25 17:09:22 +00:00
http_prefix, translate,
2021-12-04 16:59:50 +00:00
False, False,
False, None, rssIconAtTop, True,
True, theme, accessKeys,
2021-12-25 18:05:01 +00:00
shared_items_federated_domains)
2021-07-05 20:24:43 +00:00
profileHeaderStr += \
' </td>\n' + \
' <td valign="top" class="col-center">\n'
profileStr = profileHeaderStr
2021-12-25 16:17:53 +00:00
cssFilename = base_dir + '/epicyon-profile.css'
if os.path.isfile(base_dir + '/epicyon.css'):
cssFilename = base_dir + '/epicyon.css'
licenseStr = ''
bannerFile, bannerFilename = \
2021-12-25 16:17:53 +00:00
getBannerFile(base_dir, nickname, domain, theme)
profileStr += \
_htmlFrontScreenPosts(recentPostsCache, maxRecentPosts,
translate,
2021-12-25 17:09:22 +00:00
base_dir, http_prefix,
nickname, domain, port,
session, cachedWebfingers, personCache,
projectVersion,
2021-12-25 17:15:52 +00:00
yt_replace_domain,
2021-09-18 17:08:14 +00:00
twitterReplacementDomain,
2020-12-23 23:59:49 +00:00
showPublishedDateOnly,
peertubeInstances,
2021-03-09 19:52:10 +00:00
allowLocalNetworkAccess,
theme, systemLanguage,
2021-12-25 18:23:12 +00:00
max_like_count,
2021-10-21 13:08:21 +00:00
signingPrivateKeyPem,
2021-12-25 18:12:13 +00:00
CWlists, lists_enabled) + licenseStr
# Footer which is only used for system accounts
profileFooterStr = ' </td>\n'
profileFooterStr += ' <td valign="top" class="col-right">\n'
profileFooterStr += \
2021-12-25 16:17:53 +00:00
getRightColumnContent(base_dir, 'news', domainFull,
2021-12-25 17:09:22 +00:00
http_prefix, translate,
2020-12-09 13:31:54 +00:00
False, False, newswire, False,
False, None, False, False,
2021-02-05 11:41:45 +00:00
False, True, authorized, True, theme,
2021-04-23 19:06:34 +00:00
defaultTimeline, accessKeys)
2021-07-05 20:24:43 +00:00
profileFooterStr += \
' </td>\n' + \
' </tr>\n' + \
' </tbody>\n' + \
'</table>\n'
2021-01-11 19:46:21 +00:00
instanceTitle = \
2021-12-25 16:17:53 +00:00
getConfigParam(base_dir, 'instanceTitle')
profileStr = \
htmlHeaderWithExternalStyle(cssFilename, instanceTitle, None) + \
profileStr + profileFooterStr + htmlFooter()
return profileStr