From 1fc5750174bb05eb20147613f966f86e5f781cb1 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 19 Oct 2019 13:37:35 +0100 Subject: [PATCH] Update html post cache as new posts arrive --- daemon.py | 2 +- inbox.py | 34 +++++++++++++++++++++++++++++++--- webinterface.py | 4 ++-- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/daemon.py b/daemon.py index ce391e3ea..e0d8dd433 100644 --- a/daemon.py +++ b/daemon.py @@ -4825,7 +4825,7 @@ def runDaemon(projectVersion, \ domain,port,useTor,httpd.federationList, \ httpd.ocapAlways,maxReplies, \ domainMaxPostsPerDay,accountMaxPostsPerDay, \ - allowDeletion,debug,maxMentions, \ + allowDeletion,debug,maxMentions,httpd.translate, \ httpd.acceptedCaps),daemon=True) if not unitTest: httpd.thrWatchdog= \ diff --git a/inbox.py b/inbox.py index 474f492ac..e33390593 100644 --- a/inbox.py +++ b/inbox.py @@ -47,6 +47,28 @@ from posts import downloadAnnounce from posts import isDM from posts import isReply from posts import sendSignedJson +from webinterface import individualPostAsHtml +from webinterface import getIconsDir + +def inboxStorePostToHtmlCache(translate: {}, \ + baseDir: str,httpPrefix: str, \ + session,wfRequest: {},personCache: {}, \ + nickname: str,domain: str,port: int, \ + postJsonObject: {}, \ + allowDeletion: bool) -> None: + """Converts the json post into html and stores it in a cache + This enables the post to be quickly displayed later + """ + pageNumber=1 + showAvatarOptions=True + avatarUrl=None + individualPostAsHtml(getIconsDir(baseDir),translate,pageNumber, \ + baseDir,session,wfRequest,personCache, \ + nickname,domain,port,item,avatarUrl,True, \ + allowDeletion, \ + httpPrefix,__version__,boxName, \ + not isDM(postJsonObject), \ + True,True,False,True) def validInbox(baseDir: str,nickname: str,domain: str) -> bool: """Checks whether files were correctly saved to the inbox @@ -1489,7 +1511,7 @@ def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \ acceptedCaps: [], \ queueFilename :str,destinationFilename :str, \ maxReplies: int,allowDeletion: bool, \ - maxMentions: int) -> bool: + maxMentions: int,translate: {}) -> bool: """ Anything which needs to be done after capabilities checks have passed """ actor=keyId @@ -1614,6 +1636,11 @@ def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \ inboxUpdateCalendar(baseDir,handle,postJsonObject) + inboxStorePostToHtmlCache(translate,baseDir,httpPrefix, \ + session,cachedWebfingers,personCache, \ + handle.split('@')[0],domain,port, \ + postJsonObject,allowDeletion) + # send the post out to group members if isGroup: sendToGroupMembers(session,baseDir,handle,port,postJsonObject, \ @@ -1662,6 +1689,7 @@ def runInboxQueue(projectVersion: str, \ ocapAlways: bool,maxReplies: int, \ domainMaxPostsPerDay: int,accountMaxPostsPerDay: int, \ allowDeletion: bool,debug: bool,maxMentions: int, \ + translate: {}, \ acceptedCaps=["inbox:write","objects:read"]) -> None: """Processes received items and moves them to the appropriate directories @@ -2021,7 +2049,7 @@ def runInboxQueue(projectVersion: str, \ debug,acceptedCaps, \ queueFilename,destination, \ maxReplies,allowDeletion, \ - maxMentions) + maxMentions,translate) else: if debug: print('DEBUG: object capabilities check has failed') @@ -2039,7 +2067,7 @@ def runInboxQueue(projectVersion: str, \ debug,acceptedCaps, \ queueFilename,destination, \ maxReplies,allowDeletion, \ - maxMentions) + maxMentions,translate) if debug: pprint(queueJson['post']) print('No capability list within post') diff --git a/webinterface.py b/webinterface.py index 0daf46d3a..17b9faaf4 100644 --- a/webinterface.py +++ b/webinterface.py @@ -1777,7 +1777,7 @@ def individualPostAsHtml(iconsDir: str,translate: {}, \ session,wfRequest: {},personCache: {}, \ nickname: str,domain: str,port: int, \ postJsonObject: {}, \ - avatarUrl: str, showAvatarDropdown: bool, + avatarUrl: str, showAvatarOptions: bool, allowDeletion: bool, \ httpPrefix: str, projectVersion: str, \ boxName: str, \ @@ -2030,7 +2030,7 @@ def individualPostAsHtml(iconsDir: str,translate: {}, \ ' Avatar' \ ' ' - if showAvatarDropdown and fullDomain+'/users/'+nickname not in postJsonObject['actor']: + if showAvatarOptions and fullDomain+'/users/'+nickname not in postJsonObject['actor']: avatarImageInPost= \ '
' \ ' ' \