From 7058b6e2db29f7301aae6e71e4ab0792d153b275 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 6 Dec 2021 12:42:05 +0000 Subject: [PATCH] Tidying --- utils.py | 8 ++++++++ webapp_post.py | 41 +++++++++++++---------------------------- 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/utils.py b/utils.py index 98814262d..e71f8c0c7 100644 --- a/utils.py +++ b/utils.py @@ -600,6 +600,14 @@ def removeIdEnding(idStr: str) -> str: return idStr +def removeHashFromPostId(postId: str) -> str: + """Removes any has from a post id + """ + if '#' not in postId: + return postId + return postId.split('#')[0] + + def getProtocolPrefixes() -> []: """Returns a list of valid prefixes """ diff --git a/webapp_post.py b/webapp_post.py index 856b7effb..279a436a8 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -23,6 +23,7 @@ from posts import postIsMuted from posts import getPersonBox from posts import downloadAnnounce from posts import populateRepliesJson +from utils import removeHashFromPostId from utils import removeHtml from utils import getActorLanguagesList from utils import getBaseContentFromPost @@ -390,11 +391,8 @@ def _getReplyIconHtml(baseDir: str, nickname: str, domain: str, return replyStr # reply is permitted - create reply icon - if '#' not in postJsonObject['object']['id']: - replyToLink = removeIdEnding(postJsonObject['object']['id']) - else: - replyToLink = \ - removeIdEnding(postJsonObject['object']['id'].split('#')[0]) + replyToLink = removeHashFromPostId(postJsonObject['object']['id']) + replyToLink = removeIdEnding(replyToLink) # see Mike MacGirvin's replyTo suggestion if postJsonObject['object'].get('replyTo'): @@ -575,11 +573,8 @@ def _getAnnounceIconHtml(isAnnounced: bool, unannounceLinkStr = '?unannounce=' + \ removeIdEnding(announceJsonObject['id']) - if '#' not in postJsonObject['object']['id']: - announcePostId = removeIdEnding(postJsonObject['object']['id']) - else: - announcePostId = \ - removeIdEnding(postJsonObject['object']['id'].split('#')[0]) + announcePostId = removeHashFromPostId(postJsonObject['object']['id']) + announcePostId = removeIdEnding(announcePostId) announceLinkStr = '?' + \ announceLink + '=' + announcePostId + pageNumberParam announceStr = \ @@ -647,10 +642,8 @@ def _getLikeIconHtml(nickname: str, domainFull: str, likeStr += '\n' - if '#' not in postJsonObject['id']: - likePostId = removeIdEnding(postJsonObject['id']) - else: - likePostId = removeIdEnding(postJsonObject['id'].split('#')[0]) + likePostId = removeHashFromPostId(postJsonObject['id']) + likePostId = removeIdEnding(likePostId) likeStr += \ '