diff --git a/posts.py b/posts.py index 20dac08e4..05e68a497 100644 --- a/posts.py +++ b/posts.py @@ -31,6 +31,7 @@ from session import postImage from webfinger import webfingerHandle from httpsig import createSignedHeader from siteactive import siteIsActive +from utils import rejectPostId from utils import removeInvalidChars from utils import fileLastModified from utils import isPublicPost @@ -3884,14 +3885,7 @@ def _rejectAnnounce(announceFilename: str, announcePostId: str): """Marks an announce as rejected """ - # reject the announce activity - announcePostFilename = \ - locatePost(baseDir, nickname, domain, announcePostId) - if announcePostFilename: - rejectAnnounceFile = open(announcePostFilename + '.reject', "w+") - if rejectAnnounceFile: - rejectAnnounceFile.write('\n') - rejectAnnounceFile.close() + rejectPostId(baseDir, nickname, domain, announcePostId) # reject the post referenced by the announce activity object if not os.path.isfile(announceFilename + '.reject'): diff --git a/utils.py b/utils.py index 859b138d8..33535dc78 100644 --- a/utils.py +++ b/utils.py @@ -2034,3 +2034,16 @@ def camelCaseSplit(text: str) -> str: for word in matches: resultStr += word.group(0) + ' ' return resultStr.strip() + + +def rejectPostId(baseDir: str, nickname: str, domain: str, + postId: str) -> None: + """ Marks the given post as rejected + """ + postFilename = locatePost(baseDir, nickname, domain, postId) + if not postFilename: + return + rejectFile = open(postFilename + '.reject', "w+") + if rejectFile: + rejectFile.write('\n') + rejectFile.close() diff --git a/webapp_post.py b/webapp_post.py index 2dfee6d26..035f8bddb 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -22,6 +22,7 @@ from posts import getPersonBox from posts import isDM from posts import downloadAnnounce from posts import populateRepliesJson +from utils import rejectPostId from utils import isRecentPost from utils import getConfigParam from utils import getFullDomain @@ -1291,14 +1292,7 @@ def individualPostAsHtml(allowDownloads: bool, allowLocalNetworkAccess) if not postJsonAnnounce: # if the announce could not be downloaded then mark it as rejected - announceFilename = \ - locatePost(baseDir, nickname, domain, - postJsonObject['id']) - if announceFilename: - rejectFile = open(announceFilename + '.reject', "w+") - if rejectFile: - rejectFile.write('\n') - rejectFile.close() + rejectPostId(baseDir, nickname, domain, postJsonObject['id']) return '' postJsonObject = postJsonAnnounce