From 13e4d6ce3ac020e97a1eb0dd0d4856d8badd4ef6 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 12 Oct 2020 12:51:37 +0100 Subject: [PATCH] Newswire screen for mobile --- daemon.py | 28 +++++++++++++++++ webinterface.py | 83 ++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 107 insertions(+), 4 deletions(-) diff --git a/daemon.py b/daemon.py index e84d7187c..457b96e91 100644 --- a/daemon.py +++ b/daemon.py @@ -142,6 +142,7 @@ from webinterface import htmlNewPost from webinterface import htmlFollowConfirm from webinterface import htmlCalendar from webinterface import htmlSearch +from webinterface import htmlNewswireMobile from webinterface import htmlSearchEmoji from webinterface import htmlSearchEmojiTextEntry from webinterface import htmlUnfollowConfirm @@ -9152,6 +9153,33 @@ class PubServer(BaseHTTPRequestHandler): 'search screen shown') return + if htmlGET and '/users/' in self.path: + if self.path.endswith('/newswire'): + nickname = getNicknameFromActor(self.path) + if not nickname: + self._404() + self.server.GETbusy = False + return + boxname = self.path.replace('/users/' + nickname, '') + if not boxname: + self._404() + self.server.GETbusy = False + return + timelinePath = '/users/' + nickname + '/' + boxname + msg = htmlNewswireMobile(self.server.baseDir, + nickname, + self.server.domain, + self.server.domainFull, + self.server.httpPrefix, + self.server.translate, + self.server.newswire, + self.server.positiveVoting, + timelinePath) + self._set_headers('text/html', len(msg), cookie, callingDomain) + self._write(msg) + self.server.GETbusy = False + return + self._benchmarkGETtimings(GETstartTime, GETtimings, 'hashtag search done', 'search screen shown done') diff --git a/webinterface.py b/webinterface.py index 18390a984..5a0fb22a6 100644 --- a/webinterface.py +++ b/webinterface.py @@ -5572,7 +5572,8 @@ def htmlNewswire(newswire: str, nickname: str, moderator: bool, def getRightColumnContent(baseDir: str, nickname: str, domainFull: str, httpPrefix: str, translate: {}, iconsDir: str, moderator: bool, editor: bool, - newswire: {}, positiveVoting: bool) -> str: + newswire: {}, positiveVoting: bool, + showBackButton: bool, timelinePath: str) -> str: """Returns html content for the right column """ htmlStr = '' @@ -5609,6 +5610,12 @@ def getRightColumnContent(baseDir: str, nickname: str, domainFull: str, if editImageClass == 'rightColEdit': htmlStr += '\n
\n' + if showBackButton: + htmlStr += \ + ' ' + \ + '\n' + if editor: if os.path.isfile(baseDir + '/accounts/newswiremoderation.txt'): # show the edit icon highlighted @@ -5649,6 +5656,71 @@ def getRightColumnContent(baseDir: str, nickname: str, domainFull: str, return htmlStr +def htmlNewswireMobile(baseDir: str, nickname: str, + domain: str, domainFull: str, + httpPrefix: str, translate: {}, + newswire: {}, + positiveVoting: bool, + timelinePath: str) -> str: + """Shows the mobile version of the newswire right column + """ + htmlStr = '' + + # the css filename + cssFilename = baseDir + '/epicyon-profile.css' + if os.path.isfile(baseDir + '/epicyon.css'): + cssFilename = baseDir + '/epicyon.css' + + # filename of the banner shown at the top + bannerFile = 'banner.png' + bannerFilename = baseDir + '/accounts/' + \ + nickname + '@' + domain + '/' + bannerFile + if not os.path.isfile(bannerFilename): + bannerFile = 'banner.jpg' + bannerFilename = baseDir + '/accounts/' + \ + nickname + '@' + domain + '/' + bannerFile + if not os.path.isfile(bannerFilename): + bannerFile = 'banner.gif' + bannerFilename = baseDir + '/accounts/' + \ + nickname + '@' + domain + '/' + bannerFile + if not os.path.isfile(bannerFilename): + bannerFile = 'banner.avif' + bannerFilename = baseDir + '/accounts/' + \ + nickname + '@' + domain + '/' + bannerFile + if not os.path.isfile(bannerFilename): + bannerFile = 'banner.webp' + + profileStyle = None + with open(cssFilename, 'r') as cssFile: + # load css + profileStyle = \ + cssFile.read().replace('banner.png', + '/users/' + nickname + '/' + bannerFile) + # replace any https within the css with whatever prefix is needed + if httpPrefix != 'https': + profileStyle = \ + profileStyle.replace('https://', + httpPrefix + '://') + + iconsDir = getIconsDir(baseDir) + + # is the user a moderator? + moderator = isModerator(baseDir, nickname) + + # is the user a site editor? + editor = isEditor(baseDir, nickname) + + htmlStr = htmlHeader(cssFilename, profileStyle) + htmlStr += \ + getRightColumnContent(baseDir, nickname, domainFull, + httpPrefix, translate, + iconsDir, moderator, editor, + newswire, positiveVoting, + True, timelinePath) + htmlStr += htmlFooter() + return htmlStr + + def htmlTimeline(defaultTimeline: str, recentPostsCache: {}, maxRecentPosts: int, translate: {}, pageNumber: int, @@ -6137,7 +6209,8 @@ def htmlTimeline(defaultTimeline: str, # the newswire button to show right column links tlStr += \ - ' | ' + translate['News'] + \
@@ -6145,7 +6218,8 @@ def htmlTimeline(defaultTimeline: str,
 
     # the links button to show left column links
     tlStr += \
-        '        <a class=| ' + translate['Edit Links'] + \
@@ -6319,7 +6393,8 @@ def htmlTimeline(defaultTimeline: str,
     rightColumnStr = getRightColumnContent(baseDir, nickname, domainFull,
                                            httpPrefix, translate, iconsDir,
                                            moderator, editor,
-                                           newswire, positiveVoting)
+                                           newswire, positiveVoting,
+                                           False, None)
     tlStr += '  <td valign=' + \ rightColumnStr + ' \n' tlStr += ' \n'