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
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

View File

@ -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,