From 92c210175c1b3fc2dbf7601aa7363ac47a578d8e Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 7 Oct 2020 18:36:38 +0100 Subject: [PATCH] Get news timeline from news account outbox --- daemon.py | 84 +++++++++++++++++++++++++++++++++++-------------- webinterface.py | 19 ----------- 2 files changed, 61 insertions(+), 42 deletions(-) diff --git a/daemon.py b/daemon.py index cde615e7f..075e9d44a 100644 --- a/daemon.py +++ b/daemon.py @@ -120,7 +120,6 @@ from webinterface import htmlInboxDMs from webinterface import htmlInboxReplies from webinterface import htmlInboxMedia from webinterface import htmlInboxBlogs -from webinterface import htmlInboxNews from webinterface import htmlUnblockConfirm from webinterface import htmlPersonOptions from webinterface import htmlIndividualPost @@ -220,6 +219,8 @@ maxPostsInMediaFeed = 6 # Blogs can be longer, so don't show many per page maxPostsInBlogsFeed = 4 +maxPostsInNewsFeed = 10 + # Maximum number of entries in returned rss.xml maxPostsInRSSFeed = 10 @@ -6498,9 +6499,24 @@ class PubServer(BaseHTTPRequestHandler): """ if '/users/' in path: if authorized: + currNickname = path.split('/users/')[1] + if '/' in currNickname: + currNickname = currNickname.split('/')[0] + newsPath = path.replace('/' + currNickname + '/', '/news/') + inboxNewsFeed = \ + personBoxJson(self.server.recentPostsCache, + self.server.session, + baseDir, + domain, + port, + newsPath, + httpPrefix, + maxPostsInNewsFeed, 'outbox', + True) + if not inboxNewsFeed: + inboxNewsFeed = [] if self._requestHTTP(): - nickname = path.replace('/users/', '') - nickname = nickname.replace('/tlnews', '') + nickname = 'news' pageNumber = 1 if '?page=' in nickname: pageNumber = nickname.split('?page=')[1] @@ -6509,25 +6525,38 @@ class PubServer(BaseHTTPRequestHandler): pageNumber = int(pageNumber) else: pageNumber = 1 + if 'page=' not in path: + # if no page was specified then show the first + inboxNewsFeed = \ + personBoxJson(self.server.recentPostsCache, + self.server.session, + baseDir, + domain, + port, + newsPath + '?page=1', + httpPrefix, + maxPostsInBlogsFeed, 'outbox', + True) msg = \ - htmlInboxNews(self.server.defaultTimeline, - self.server.recentPostsCache, - self.server.maxRecentPosts, - self.server.translate, - pageNumber, maxPostsInBlogsFeed, - self.server.session, - baseDir, - self.server.cachedWebfingers, - self.server.personCache, - nickname, - domain, - port, - self.server.allowDeletion, - httpPrefix, - self.server.projectVersion, - self._isMinimal(nickname), - self.server.YTReplacementDomain, - self.server.newswire) + htmlInboxBlogs(self.server.defaultTimeline, + self.server.recentPostsCache, + self.server.maxRecentPosts, + self.server.translate, + pageNumber, maxPostsInNewsFeed, + self.server.session, + baseDir, + self.server.cachedWebfingers, + self.server.personCache, + nickname, + domain, + port, + inboxNewsFeed, + self.server.allowDeletion, + httpPrefix, + self.server.projectVersion, + self._isMinimal(nickname), + self.server.YTReplacementDomain, + self.server.newswire) msg = msg.encode('utf-8') self._set_headers('text/html', len(msg), cookie, callingDomain) @@ -6535,12 +6564,21 @@ class PubServer(BaseHTTPRequestHandler): self._benchmarkGETtimings(GETstartTime, GETtimings, 'show blogs 2 done', 'show news 2') + else: + # don't need authenticated fetch here because there is + # already the authorization check + msg = json.dumps(inboxNewsFeed, + ensure_ascii=False) + msg = msg.encode('utf-8') + self._set_headers('application/json', + len(msg), + None, callingDomain) + self._write(msg) self.server.GETbusy = False return True else: if debug: - nickname = path.replace('/users/', '') - nickname = nickname.replace('/tlnews', '') + nickname = 'news' print('DEBUG: ' + nickname + ' was not authorized to access ' + path) if path != '/tlnews': diff --git a/webinterface.py b/webinterface.py index f652fe128..c0d0ed9cf 100644 --- a/webinterface.py +++ b/webinterface.py @@ -6340,25 +6340,6 @@ def htmlInboxBlogs(defaultTimeline: str, minimal, YTReplacementDomain, newswire) -def htmlInboxNews(defaultTimeline: str, - recentPostsCache: {}, maxRecentPosts: int, - translate: {}, pageNumber: int, itemsPerPage: int, - session, baseDir: str, wfRequest: {}, personCache: {}, - nickname: str, domain: str, port: int, - allowDeletion: bool, - httpPrefix: str, projectVersion: str, - minimal: bool, YTReplacementDomain: str, - newswire: {}) -> str: - """Show the news timeline as html - """ - return htmlTimeline(defaultTimeline, recentPostsCache, maxRecentPosts, - translate, pageNumber, - itemsPerPage, session, baseDir, wfRequest, personCache, - nickname, domain, port, {}, 'tlnews', - allowDeletion, httpPrefix, projectVersion, False, - minimal, YTReplacementDomain, newswire) - - def htmlModeration(defaultTimeline: str, recentPostsCache: {}, maxRecentPosts: int, translate: {}, pageNumber: int, itemsPerPage: int,