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