mirror of https://gitlab.com/bashrc2/epicyon
Improve consolidation of mentions during creation of new posts
parent
04e7addaf7
commit
1b2e1befc3
36
posts.py
36
posts.py
|
@ -32,6 +32,7 @@ from webfinger import webfingerHandle
|
||||||
from httpsig import createSignedHeader
|
from httpsig import createSignedHeader
|
||||||
from siteactive import siteIsActive
|
from siteactive import siteIsActive
|
||||||
from languages import understoodPostLanguage
|
from languages import understoodPostLanguage
|
||||||
|
from utils import getUserPaths
|
||||||
from utils import invalidCiphertext
|
from utils import invalidCiphertext
|
||||||
from utils import hasObjectStringType
|
from utils import hasObjectStringType
|
||||||
from utils import removeIdEnding
|
from utils import removeIdEnding
|
||||||
|
@ -1259,6 +1260,29 @@ def _createPostPlaceAndTime(eventDate: str, endDate: str,
|
||||||
return eventDateStr
|
return eventDateStr
|
||||||
|
|
||||||
|
|
||||||
|
def _consolidateActorsList(actorsList: []) -> None:
|
||||||
|
""" consolidate duplicated actors
|
||||||
|
https://domain/@nick gets merged with https://domain/users/nick
|
||||||
|
"""
|
||||||
|
possibleDuplicateActors = []
|
||||||
|
for ccActor in actorsList:
|
||||||
|
if '/@' in ccActor:
|
||||||
|
if ccActor not in possibleDuplicateActors:
|
||||||
|
possibleDuplicateActors.append(ccActor)
|
||||||
|
if possibleDuplicateActors:
|
||||||
|
uPaths = getUserPaths()
|
||||||
|
removeActors = []
|
||||||
|
for ccActor in possibleDuplicateActors:
|
||||||
|
for usrPath in uPaths:
|
||||||
|
ccActorFull = ccActor.replace('/@', usrPath)
|
||||||
|
if ccActorFull in actorsList:
|
||||||
|
if ccActor not in removeActors:
|
||||||
|
removeActors.append(ccActor)
|
||||||
|
break
|
||||||
|
for ccActor in removeActors:
|
||||||
|
actorsList.remove(ccActor)
|
||||||
|
|
||||||
|
|
||||||
def _createPostMentions(ccUrl: str, newPost: {},
|
def _createPostMentions(ccUrl: str, newPost: {},
|
||||||
toRecipients: [], tags: []) -> None:
|
toRecipients: [], tags: []) -> None:
|
||||||
"""Updates mentions for a new post
|
"""Updates mentions for a new post
|
||||||
|
@ -1267,9 +1291,10 @@ def _createPostMentions(ccUrl: str, newPost: {},
|
||||||
return
|
return
|
||||||
if len(ccUrl) == 0:
|
if len(ccUrl) == 0:
|
||||||
return
|
return
|
||||||
newPost['cc'] = [ccUrl]
|
|
||||||
if newPost.get('object'):
|
if newPost.get('object'):
|
||||||
newPost['object']['cc'] = [ccUrl]
|
if ccUrl not in newPost['object']['cc']:
|
||||||
|
newPost['object']['cc'] = [ccUrl] + newPost['object']['cc']
|
||||||
|
|
||||||
# if this is a public post then include any mentions in cc
|
# if this is a public post then include any mentions in cc
|
||||||
toCC = newPost['object']['cc']
|
toCC = newPost['object']['cc']
|
||||||
|
@ -1283,6 +1308,13 @@ def _createPostMentions(ccUrl: str, newPost: {},
|
||||||
if tag['href'] not in toCC:
|
if tag['href'] not in toCC:
|
||||||
newPost['object']['cc'].append(tag['href'])
|
newPost['object']['cc'].append(tag['href'])
|
||||||
|
|
||||||
|
_consolidateActorsList(newPost['object']['cc'])
|
||||||
|
newPost['cc'] = newPost['object']['cc']
|
||||||
|
else:
|
||||||
|
if ccUrl not in newPost['cc']:
|
||||||
|
newPost['cc'] = [ccUrl] + newPost['cc']
|
||||||
|
_consolidateActorsList(['cc'])
|
||||||
|
|
||||||
|
|
||||||
def _createPostModReport(baseDir: str,
|
def _createPostModReport(baseDir: str,
|
||||||
isModerationReport: bool, newPost: {},
|
isModerationReport: bool, newPost: {},
|
||||||
|
|
17
tests.py
17
tests.py
|
@ -4240,6 +4240,7 @@ def _testReplyToPublicPost(baseDir: str) -> None:
|
||||||
mediaType = None
|
mediaType = None
|
||||||
imageDescription = 'Some description'
|
imageDescription = 'Some description'
|
||||||
city = 'London, England'
|
city = 'London, England'
|
||||||
|
testInReplyTo = postId
|
||||||
testInReplyToAtomUri = None
|
testInReplyToAtomUri = None
|
||||||
testSubject = None
|
testSubject = None
|
||||||
testSchedulePost = False
|
testSchedulePost = False
|
||||||
|
@ -4255,7 +4256,7 @@ def _testReplyToPublicPost(baseDir: str) -> None:
|
||||||
content, followersOnly, saveToFile,
|
content, followersOnly, saveToFile,
|
||||||
clientToServer, commentsEnabled,
|
clientToServer, commentsEnabled,
|
||||||
attachImageFilename, mediaType,
|
attachImageFilename, mediaType,
|
||||||
imageDescription, city, postId,
|
imageDescription, city, testInReplyTo,
|
||||||
testInReplyToAtomUri,
|
testInReplyToAtomUri,
|
||||||
testSubject, testSchedulePost,
|
testSubject, testSchedulePost,
|
||||||
testEventDate, testEventTime, testLocation,
|
testEventDate, testEventTime, testLocation,
|
||||||
|
@ -4276,8 +4277,20 @@ def _testReplyToPublicPost(baseDir: str) -> None:
|
||||||
assert len(reply['object']['cc']) >= 1
|
assert len(reply['object']['cc']) >= 1
|
||||||
assert reply['object']['cc'][0].endswith(nickname + '/followers')
|
assert reply['object']['cc'][0].endswith(nickname + '/followers')
|
||||||
assert len(reply['object']['tag']) == 1
|
assert len(reply['object']['tag']) == 1
|
||||||
|
if len(reply['object']['cc']) != 2:
|
||||||
|
print('reply["object"]["cc"]: ' + str(reply['object']['cc']))
|
||||||
assert len(reply['object']['cc']) == 2
|
assert len(reply['object']['cc']) == 2
|
||||||
assert reply['object']['cc'][1] == httpPrefix + '://rat.site/@ninjarodent'
|
assert reply['object']['cc'][1] == \
|
||||||
|
httpPrefix + '://rat.site/users/ninjarodent'
|
||||||
|
|
||||||
|
assert len(reply['to']) == 1
|
||||||
|
assert reply['to'][0].endswith('#Public')
|
||||||
|
assert len(reply['cc']) >= 1
|
||||||
|
assert reply['cc'][0].endswith(nickname + '/followers')
|
||||||
|
if len(reply['cc']) != 2:
|
||||||
|
print('reply["cc"]: ' + str(reply['cc']))
|
||||||
|
assert len(reply['cc']) == 2
|
||||||
|
assert reply['cc'][1] == httpPrefix + '://rat.site/users/ninjarodent'
|
||||||
|
|
||||||
|
|
||||||
def _getFunctionCallArgs(name: str, lines: [], startLineCtr: int) -> []:
|
def _getFunctionCallArgs(name: str, lines: [], startLineCtr: int) -> []:
|
||||||
|
|
Loading…
Reference in New Issue