From e70a9b96c591d1094d6a37354b94cdf7a3055eb4 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 7 May 2021 22:10:55 +0100 Subject: [PATCH] Showing announced posts --- announce.py | 31 ++++++------------------------- webapp_post.py | 10 +++++++--- 2 files changed, 13 insertions(+), 28 deletions(-) diff --git a/announce.py b/announce.py index 5ec2ee386..e42addf0d 100644 --- a/announce.py +++ b/announce.py @@ -73,34 +73,15 @@ def outboxAnnounce(recentPostsCache: {}, return False -def announcedByPerson(postJsonObject: {}, nickname: str, domain: str) -> bool: +def announcedByPerson(isAnnounced: bool, postJsonObject: {}, + nickname: str, domainFull: str) -> bool: """Returns True if the given post is announced by the given person """ - if not postJsonObject.get('type'): + if not postJsonObject.get('actor'): return False - if not postJsonObject.get('object'): - return False - if isinstance(postJsonObject['object'], str): - if postJsonObject['type'] == 'Announce' and \ - postJsonObject.get('actor'): - actorMatch = domain + '/users/' + nickname - if postJsonObject['actor'].endswith(actorMatch): - return True - elif not isinstance(postJsonObject['object'], dict): - return False - # not to be confused with shared items - if not postJsonObject['object'].get('shares'): - return False - if not isinstance(postJsonObject['object']['shares'], dict): - return False - if not postJsonObject['object']['shares'].get('items'): - return False - if not isinstance(postJsonObject['object']['shares']['items'], list): - return False - actorMatch = domain + '/users/' + nickname - for item in postJsonObject['object']['shares']['items']: - if item['actor'].endswith(actorMatch): - return True + if isAnnounced and \ + postJsonObject['actor'].endswith(domainFull + '/users/' + nickname): + return True return False diff --git a/webapp_post.py b/webapp_post.py index e965f484c..98fc78074 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -385,7 +385,8 @@ def _getEditIconHtml(baseDir: str, nickname: str, domainFull: str, return editStr -def _getAnnounceIconHtml(nickname: str, domainFull: str, +def _getAnnounceIconHtml(isAnnounced: bool, + nickname: str, domainFull: str, postJsonObject: {}, isPublicRepeat: bool, isModerationPost: bool, @@ -412,7 +413,8 @@ def _getAnnounceIconHtml(nickname: str, domainFull: str, announceLink = 'repeatprivate' announceTitle = translate['Repeat this post'] - if announcedByPerson(postJsonObject, nickname, domainFull): + if announcedByPerson(isAnnounced, + postJsonObject, nickname, domainFull): announceIcon = 'repeat.png' announceEmoji = '🔁 ' announceLink = 'unrepeat' @@ -1311,6 +1313,7 @@ def individualPostAsHtml(allowDownloads: bool, baseDir, announceFilename, postActor, domainFull, False) + # create a file for use by text-to-speech if isRecentPost(postJsonObject): if postJsonObject.get('actor'): if not os.path.isfile(announceFilename + '.tts'): @@ -1407,7 +1410,8 @@ def individualPostAsHtml(allowDownloads: bool, translate, isEvent) announceStr = \ - _getAnnounceIconHtml(nickname, domainFull, + _getAnnounceIconHtml(isAnnounced, + nickname, domainFull, postJsonObject, isPublicRepeat, isModerationPost,