Showing announced posts

main
Bob Mottram 2021-05-07 22:10:55 +01:00
parent 7c5317224a
commit e70a9b96c5
2 changed files with 13 additions and 28 deletions

View File

@ -73,34 +73,15 @@ def outboxAnnounce(recentPostsCache: {},
return False 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 """Returns True if the given post is announced by the given person
""" """
if not postJsonObject.get('type'): if not postJsonObject.get('actor'):
return False return False
if not postJsonObject.get('object'): if isAnnounced and \
return False postJsonObject['actor'].endswith(domainFull + '/users/' + nickname):
if isinstance(postJsonObject['object'], str): return True
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
return False return False

View File

@ -385,7 +385,8 @@ def _getEditIconHtml(baseDir: str, nickname: str, domainFull: str,
return editStr return editStr
def _getAnnounceIconHtml(nickname: str, domainFull: str, def _getAnnounceIconHtml(isAnnounced: bool,
nickname: str, domainFull: str,
postJsonObject: {}, postJsonObject: {},
isPublicRepeat: bool, isPublicRepeat: bool,
isModerationPost: bool, isModerationPost: bool,
@ -412,7 +413,8 @@ def _getAnnounceIconHtml(nickname: str, domainFull: str,
announceLink = 'repeatprivate' announceLink = 'repeatprivate'
announceTitle = translate['Repeat this post'] announceTitle = translate['Repeat this post']
if announcedByPerson(postJsonObject, nickname, domainFull): if announcedByPerson(isAnnounced,
postJsonObject, nickname, domainFull):
announceIcon = 'repeat.png' announceIcon = 'repeat.png'
announceEmoji = '🔁 ' announceEmoji = '🔁 '
announceLink = 'unrepeat' announceLink = 'unrepeat'
@ -1311,6 +1313,7 @@ def individualPostAsHtml(allowDownloads: bool,
baseDir, announceFilename, baseDir, announceFilename,
postActor, domainFull, False) postActor, domainFull, False)
# create a file for use by text-to-speech
if isRecentPost(postJsonObject): if isRecentPost(postJsonObject):
if postJsonObject.get('actor'): if postJsonObject.get('actor'):
if not os.path.isfile(announceFilename + '.tts'): if not os.path.isfile(announceFilename + '.tts'):
@ -1407,7 +1410,8 @@ def individualPostAsHtml(allowDownloads: bool,
translate, isEvent) translate, isEvent)
announceStr = \ announceStr = \
_getAnnounceIconHtml(nickname, domainFull, _getAnnounceIconHtml(isAnnounced,
nickname, domainFull,
postJsonObject, postJsonObject,
isPublicRepeat, isPublicRepeat,
isModerationPost, isModerationPost,