mirror of https://gitlab.com/bashrc2/epicyon
Merge branch 'main' of ssh://code.freedombone.net:2222/bashrc/epicyon
commit
b2e796addb
23
announce.py
23
announce.py
|
|
@ -49,7 +49,7 @@ def outboxAnnounce(recentPostsCache: {},
|
||||||
updateAnnounceCollection(recentPostsCache, baseDir, postFilename,
|
updateAnnounceCollection(recentPostsCache, baseDir, postFilename,
|
||||||
messageJson['actor'], domain, debug)
|
messageJson['actor'], domain, debug)
|
||||||
return True
|
return True
|
||||||
if messageJson['type'] == 'Undo':
|
elif messageJson['type'] == 'Undo':
|
||||||
if not isinstance(messageJson['object'], dict):
|
if not isinstance(messageJson['object'], dict):
|
||||||
return False
|
return False
|
||||||
if not messageJson['object'].get('type'):
|
if not messageJson['object'].get('type'):
|
||||||
|
|
@ -73,25 +73,14 @@ def outboxAnnounce(recentPostsCache: {},
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def announcedByPerson(postJsonObject: {}, nickname: str, domain: str) -> bool:
|
def announcedByPerson(isAnnounced: bool, postActor: str,
|
||||||
|
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('object'):
|
if not postActor:
|
||||||
return False
|
return False
|
||||||
if not isinstance(postJsonObject['object'], dict):
|
if isAnnounced and \
|
||||||
return False
|
postActor.endswith(domainFull + '/users/' + nickname):
|
||||||
# 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 True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
||||||
3
utils.py
3
utils.py
|
|
@ -1985,7 +1985,8 @@ def updateAnnounceCollection(recentPostsCache: {},
|
||||||
It's shares of posts, not shares of physical objects.
|
It's shares of posts, not shares of physical objects.
|
||||||
"""
|
"""
|
||||||
postJsonObject = loadJson(postFilename)
|
postJsonObject = loadJson(postFilename)
|
||||||
if postJsonObject:
|
if not postJsonObject:
|
||||||
|
return
|
||||||
# remove any cached version of this announce so that the announce
|
# remove any cached version of this announce so that the announce
|
||||||
# icon is changed
|
# icon is changed
|
||||||
nickname = getNicknameFromActor(actor)
|
nickname = getNicknameFromActor(actor)
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ from posts import postIsMuted
|
||||||
from posts import getPersonBox
|
from posts import getPersonBox
|
||||||
from posts import downloadAnnounce
|
from posts import downloadAnnounce
|
||||||
from posts import populateRepliesJson
|
from posts import populateRepliesJson
|
||||||
|
from utils import updateAnnounceCollection
|
||||||
from utils import isPGPEncrypted
|
from utils import isPGPEncrypted
|
||||||
from utils import isDM
|
from utils import isDM
|
||||||
from utils import rejectPostId
|
from utils import rejectPostId
|
||||||
|
|
@ -384,7 +385,9 @@ def _getEditIconHtml(baseDir: str, nickname: str, domainFull: str,
|
||||||
return editStr
|
return editStr
|
||||||
|
|
||||||
|
|
||||||
def _getAnnounceIconHtml(nickname: str, domainFull: str,
|
def _getAnnounceIconHtml(isAnnounced: bool,
|
||||||
|
postActor: str,
|
||||||
|
nickname: str, domainFull: str,
|
||||||
postJsonObject: {},
|
postJsonObject: {},
|
||||||
isPublicRepeat: bool,
|
isPublicRepeat: bool,
|
||||||
isModerationPost: bool,
|
isModerationPost: bool,
|
||||||
|
|
@ -396,7 +399,13 @@ def _getAnnounceIconHtml(nickname: str, domainFull: str,
|
||||||
"""Returns html for announce icon/button
|
"""Returns html for announce icon/button
|
||||||
"""
|
"""
|
||||||
announceStr = ''
|
announceStr = ''
|
||||||
if not isModerationPost and showRepeatIcon:
|
|
||||||
|
if not showRepeatIcon:
|
||||||
|
return announceStr
|
||||||
|
|
||||||
|
if isModerationPost:
|
||||||
|
return announceStr
|
||||||
|
|
||||||
# don't allow announce/repeat of your own posts
|
# don't allow announce/repeat of your own posts
|
||||||
announceIcon = 'repeat_inactive.png'
|
announceIcon = 'repeat_inactive.png'
|
||||||
announceLink = 'repeat'
|
announceLink = 'repeat'
|
||||||
|
|
@ -405,9 +414,11 @@ 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,
|
||||||
|
postActor, nickname, domainFull):
|
||||||
announceIcon = 'repeat.png'
|
announceIcon = 'repeat.png'
|
||||||
announceEmoji = '🔁 '
|
announceEmoji = '🔁 '
|
||||||
|
announceLink = 'unrepeat'
|
||||||
if not isPublicRepeat:
|
if not isPublicRepeat:
|
||||||
announceLink = 'unrepeatprivate'
|
announceLink = 'unrepeatprivate'
|
||||||
announceTitle = translate['Undo the repeat']
|
announceTitle = translate['Undo the repeat']
|
||||||
|
|
@ -422,8 +433,8 @@ def _getAnnounceIconHtml(nickname: str, domainFull: str,
|
||||||
|
|
||||||
announceStr += \
|
announceStr += \
|
||||||
' ' + \
|
' ' + \
|
||||||
'<img loading="lazy" title="' + translate['Repeat this post'] + \
|
'<img loading="lazy" title="' + announceTitle + \
|
||||||
'" alt="' + announceEmoji + translate['Repeat this post'] + \
|
'" alt="' + announceEmoji + announceTitle + \
|
||||||
' |" src="/icons/' + announceIcon + '"/></a>\n'
|
' |" src="/icons/' + announceIcon + '"/></a>\n'
|
||||||
return announceStr
|
return announceStr
|
||||||
|
|
||||||
|
|
@ -1295,11 +1306,17 @@ def individualPostAsHtml(allowDownloads: bool,
|
||||||
return ''
|
return ''
|
||||||
postJsonObject = postJsonAnnounce
|
postJsonObject = postJsonAnnounce
|
||||||
|
|
||||||
if isRecentPost(postJsonObject):
|
|
||||||
announceFilename = \
|
announceFilename = \
|
||||||
locatePost(baseDir, nickname, domain,
|
locatePost(baseDir, nickname, domain,
|
||||||
postJsonObject['id'])
|
postJsonObject['id'])
|
||||||
if announceFilename and postJsonObject.get('actor'):
|
if announceFilename:
|
||||||
|
updateAnnounceCollection(recentPostsCache,
|
||||||
|
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'):
|
if not os.path.isfile(announceFilename + '.tts'):
|
||||||
updateSpeaker(baseDir, httpPrefix,
|
updateSpeaker(baseDir, httpPrefix,
|
||||||
nickname, domain, domainFull,
|
nickname, domain, domainFull,
|
||||||
|
|
@ -1394,7 +1411,9 @@ def individualPostAsHtml(allowDownloads: bool,
|
||||||
translate, isEvent)
|
translate, isEvent)
|
||||||
|
|
||||||
announceStr = \
|
announceStr = \
|
||||||
_getAnnounceIconHtml(nickname, domainFull,
|
_getAnnounceIconHtml(isAnnounced,
|
||||||
|
postActor,
|
||||||
|
nickname, domainFull,
|
||||||
postJsonObject,
|
postJsonObject,
|
||||||
isPublicRepeat,
|
isPublicRepeat,
|
||||||
isModerationPost,
|
isModerationPost,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue