mirror of https://gitlab.com/bashrc2/epicyon
When liking an announce send the like to the original post
parent
709064523b
commit
5b5efce7f9
25
daemon.py
25
daemon.py
|
@ -72,6 +72,7 @@ from person import removeAccount
|
||||||
from person import canRemovePost
|
from person import canRemovePost
|
||||||
from person import personSnooze
|
from person import personSnooze
|
||||||
from person import personUnsnooze
|
from person import personUnsnooze
|
||||||
|
from posts import getOriginalPostFromAnnounceUrl
|
||||||
from posts import savePostToBox
|
from posts import savePostToBox
|
||||||
from posts import getInstanceActorKey
|
from posts import getInstanceActorKey
|
||||||
from posts import removePostInteractions
|
from posts import removePostInteractions
|
||||||
|
@ -7365,12 +7366,22 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
actorLiked = path.split('?actor=')[1]
|
actorLiked = path.split('?actor=')[1]
|
||||||
if '?' in actorLiked:
|
if '?' in actorLiked:
|
||||||
actorLiked = actorLiked.split('?')[0]
|
actorLiked = actorLiked.split('?')[0]
|
||||||
|
|
||||||
|
# if this is an announce then send the like to the original post
|
||||||
|
origActor, origPostUrl = \
|
||||||
|
getOriginalPostFromAnnounceUrl(likeUrl, baseDir,
|
||||||
|
self.postToNickname, domain)
|
||||||
|
likeUrl2 = likeUrl
|
||||||
|
if origActor and origPostUrl:
|
||||||
|
actorLiked = origActor
|
||||||
|
likeUrl2 = origPostUrl
|
||||||
|
|
||||||
likeJson = {
|
likeJson = {
|
||||||
"@context": "https://www.w3.org/ns/activitystreams",
|
"@context": "https://www.w3.org/ns/activitystreams",
|
||||||
'type': 'Like',
|
'type': 'Like',
|
||||||
'actor': likeActor,
|
'actor': likeActor,
|
||||||
'to': [actorLiked],
|
'to': [actorLiked],
|
||||||
'object': likeUrl
|
'object': likeUrl2
|
||||||
}
|
}
|
||||||
|
|
||||||
# send out the like to followers
|
# send out the like to followers
|
||||||
|
@ -7532,6 +7543,16 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
actorLiked = path.split('?actor=')[1]
|
actorLiked = path.split('?actor=')[1]
|
||||||
if '?' in actorLiked:
|
if '?' in actorLiked:
|
||||||
actorLiked = actorLiked.split('?')[0]
|
actorLiked = actorLiked.split('?')[0]
|
||||||
|
|
||||||
|
# if this is an announce then send the like to the original post
|
||||||
|
origActor, origPostUrl = \
|
||||||
|
getOriginalPostFromAnnounceUrl(likeUrl, baseDir,
|
||||||
|
self.postToNickname, domain)
|
||||||
|
likeUrl2 = likeUrl
|
||||||
|
if origActor and origPostUrl:
|
||||||
|
actorLiked = origActor
|
||||||
|
likeUrl2 = origPostUrl
|
||||||
|
|
||||||
undoLikeJson = {
|
undoLikeJson = {
|
||||||
"@context": "https://www.w3.org/ns/activitystreams",
|
"@context": "https://www.w3.org/ns/activitystreams",
|
||||||
'type': 'Undo',
|
'type': 'Undo',
|
||||||
|
@ -7541,7 +7562,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
'type': 'Like',
|
'type': 'Like',
|
||||||
'actor': undoActor,
|
'actor': undoActor,
|
||||||
'to': [actorLiked],
|
'to': [actorLiked],
|
||||||
'object': likeUrl
|
'object': likeUrl2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
49
posts.py
49
posts.py
|
@ -5040,3 +5040,52 @@ def editedPostFilename(baseDir: str, nickname: str, domain: str,
|
||||||
return ''
|
return ''
|
||||||
print(id2 + ' is an edit of ' + id1)
|
print(id2 + ' is an edit of ' + id1)
|
||||||
return prevConvPostFilename
|
return prevConvPostFilename
|
||||||
|
|
||||||
|
|
||||||
|
def getOriginalPostFromAnnounceUrl(announceUrl: str, baseDir: str,
|
||||||
|
nickname: str, domain: str) -> (str, str):
|
||||||
|
"""From the url of an announce this returns the actor and url
|
||||||
|
of the original post being announced
|
||||||
|
"""
|
||||||
|
postFilename = locatePost(baseDir, nickname, domain, announceUrl)
|
||||||
|
if not postFilename:
|
||||||
|
return None, None
|
||||||
|
announcePostJson = loadJson(postFilename, 0, 1)
|
||||||
|
if not announcePostJson:
|
||||||
|
return None, None
|
||||||
|
if not announcePostJson.get('type'):
|
||||||
|
return None, None
|
||||||
|
if announcePostJson['type'] != 'Announce':
|
||||||
|
return None, None
|
||||||
|
if not announcePostJson.get('object'):
|
||||||
|
return None, None
|
||||||
|
if not isinstance(announcePostJson['object'], str):
|
||||||
|
return None, None
|
||||||
|
# do we have the original post?
|
||||||
|
origPostId = announcePostJson['object']
|
||||||
|
origFilename = locatePost(baseDir, nickname, domain, origPostId)
|
||||||
|
actor = url = None
|
||||||
|
if origFilename:
|
||||||
|
# we have the original post
|
||||||
|
origPostJson = loadJson(origFilename, 0, 1)
|
||||||
|
if origPostJson:
|
||||||
|
url = announcePostJson['object']
|
||||||
|
if hasObjectDict(origPostJson):
|
||||||
|
if origPostJson['object'].get('attributedTo'):
|
||||||
|
actor = origPostJson['object']['attributedTo']
|
||||||
|
elif origPostJson['object'].get('actor'):
|
||||||
|
actor = origPostJson['actor']
|
||||||
|
else:
|
||||||
|
url = None
|
||||||
|
else:
|
||||||
|
# we don't have the original post
|
||||||
|
if hasUsersPath(origPostId):
|
||||||
|
# get the actor from the original post url
|
||||||
|
origNick = getNicknameFromActor(origPostId)
|
||||||
|
origDomain, origPort = getDomainFromActor(origPostId)
|
||||||
|
if origNick and origDomain:
|
||||||
|
actor = \
|
||||||
|
origPostId.split('/' + origNick + '/')[0] + \
|
||||||
|
'/' + origNick
|
||||||
|
url = origPostId
|
||||||
|
return actor, url
|
||||||
|
|
Loading…
Reference in New Issue