mirror of https://gitlab.com/bashrc2/epicyon
Fix removal of post interactions
parent
0be2e87ffa
commit
3469850199
|
@ -9214,7 +9214,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
proxyType: str, cookie: str,
|
||||
debug: str) -> bool:
|
||||
"""Shows the outbox timeline
|
||||
"""
|
||||
"""
|
||||
# get outbox feed for a person
|
||||
outboxFeed = \
|
||||
personBoxJson(self.server.recentPostsCache,
|
||||
|
|
51
posts.py
51
posts.py
|
@ -1488,6 +1488,37 @@ def jsonPinPost(baseDir: str, httpPrefix: str,
|
|||
}
|
||||
|
||||
|
||||
def regenerateIndexForBox(baseDir: str,
|
||||
nickname: str, domain: str, boxName: str) -> None:
|
||||
"""Generates an index for the given box if it doesn't exist
|
||||
Used by unit tests to artificially create an index
|
||||
"""
|
||||
boxDir = acctDir(baseDir, nickname, domain) + '/' + boxName
|
||||
boxIndexFilename = boxDir + '.index'
|
||||
|
||||
if not os.path.isdir(boxDir):
|
||||
return
|
||||
if os.path.isfile(boxIndexFilename):
|
||||
return
|
||||
|
||||
indexLines = []
|
||||
for subdir, dirs, files in os.walk(boxDir):
|
||||
for f in files:
|
||||
if ':##' not in f:
|
||||
continue
|
||||
indexLines.append(f)
|
||||
break
|
||||
|
||||
indexLines.sort(reverse=True)
|
||||
|
||||
result = ''
|
||||
with open(boxIndexFilename, 'w+') as fp:
|
||||
for line in indexLines:
|
||||
result += line + '\n'
|
||||
fp.write(line + '\n')
|
||||
print('Index generated for ' + boxName + '\n' + result)
|
||||
|
||||
|
||||
def createPublicPost(baseDir: str,
|
||||
nickname: str, domain: str, port: int, httpPrefix: str,
|
||||
content: str, followersOnly: bool, saveToFile: bool,
|
||||
|
@ -3164,7 +3195,7 @@ def removePostInteractions(postJsonObject: {}, force: bool) -> bool:
|
|||
if not force:
|
||||
# If not authorized and it's a private post
|
||||
# then just don't show it within timelines
|
||||
if not isPublicPost(postObj):
|
||||
if not isPublicPost(postJsonObject):
|
||||
return False
|
||||
else:
|
||||
postObj = postJsonObject
|
||||
|
@ -3267,6 +3298,7 @@ def _createBoxIndexed(recentPostsCache: {},
|
|||
indexBoxName = boxname
|
||||
timelineNickname = 'news'
|
||||
|
||||
originalDomain = domain
|
||||
domain = getFullDomain(domain, port)
|
||||
|
||||
boxActor = httpPrefix + '://' + domain + '/users/' + nickname
|
||||
|
@ -3300,7 +3332,7 @@ def _createBoxIndexed(recentPostsCache: {},
|
|||
postsInBox = []
|
||||
|
||||
indexFilename = \
|
||||
baseDir + '/accounts/' + timelineNickname + '@' + domain + \
|
||||
acctDir(baseDir, timelineNickname, originalDomain) + \
|
||||
'/' + indexBoxName + '.index'
|
||||
totalPostsCount = 0
|
||||
postsAddedToTimeline = 0
|
||||
|
@ -3342,22 +3374,29 @@ def _createBoxIndexed(recentPostsCache: {},
|
|||
if postUrl in recentPostsCache['index']:
|
||||
if recentPostsCache['json'].get(postUrl):
|
||||
url = recentPostsCache['json'][postUrl]
|
||||
print('Adding post to timeline: ' +
|
||||
boxname + ' ' + url)
|
||||
if _addPostStringToTimeline(url,
|
||||
boxname, postsInBox,
|
||||
boxActor):
|
||||
totalPostsCount += 1
|
||||
postsAddedToTimeline += 1
|
||||
continue
|
||||
else:
|
||||
print('Post not added to timeline')
|
||||
print('postsInBox: ' + str(len(postsInBox)))
|
||||
|
||||
# read the post from file
|
||||
fullPostFilename = \
|
||||
locatePost(baseDir, nickname,
|
||||
domain, postUrl, False)
|
||||
originalDomain, postUrl, False)
|
||||
if fullPostFilename:
|
||||
# has the post been rejected?
|
||||
if os.path.isfile(fullPostFilename + '.reject'):
|
||||
continue
|
||||
|
||||
print('Adding post to timeline: ' +
|
||||
boxname + ' ' + fullPostFilename)
|
||||
if _addPostToTimeline(fullPostFilename, boxname,
|
||||
postsInBox, boxActor):
|
||||
postsAddedToTimeline += 1
|
||||
|
@ -3366,13 +3405,16 @@ def _createBoxIndexed(recentPostsCache: {},
|
|||
print('WARN: Unable to add post ' + postUrl +
|
||||
' nickname ' + nickname +
|
||||
' timeline ' + boxname)
|
||||
print('postsInBox: ' + str(len(postsInBox)))
|
||||
else:
|
||||
if timelineNickname != nickname:
|
||||
# if this is the features timeline
|
||||
fullPostFilename = \
|
||||
locatePost(baseDir, timelineNickname,
|
||||
domain, postUrl, False)
|
||||
originalDomain, postUrl, False)
|
||||
if fullPostFilename:
|
||||
print('Adding post to timeline: ' +
|
||||
boxname + ' ' + fullPostFilename)
|
||||
if _addPostToTimeline(fullPostFilename, boxname,
|
||||
postsInBox, boxActor):
|
||||
postsAddedToTimeline += 1
|
||||
|
@ -3381,6 +3423,7 @@ def _createBoxIndexed(recentPostsCache: {},
|
|||
print('WARN: Unable to add features post ' +
|
||||
postUrl + ' nickname ' + nickname +
|
||||
' timeline ' + boxname)
|
||||
print('postsInBox: ' + str(len(postsInBox)))
|
||||
else:
|
||||
print('WARN: features timeline. ' +
|
||||
'Unable to locate post ' + postUrl)
|
||||
|
|
39
tests.py
39
tests.py
|
@ -24,6 +24,8 @@ from cache import getPersonFromCache
|
|||
from threads import threadWithTrace
|
||||
from daemon import runDaemon
|
||||
from session import createSession
|
||||
from session import getJson
|
||||
from posts import regenerateIndexForBox
|
||||
from posts import removePostInteractions
|
||||
from posts import getMentionedPeople
|
||||
from posts import validContentWarning
|
||||
|
@ -547,6 +549,7 @@ def createServerAlice(path: str, domain: str, port: int,
|
|||
testSubject, testSchedulePost,
|
||||
testEventDate, testEventTime, testLocation,
|
||||
testIsArticle, systemLanguage)
|
||||
regenerateIndexForBox(path, nickname, domain, 'outbox')
|
||||
global testServerAliceRunning
|
||||
testServerAliceRunning = True
|
||||
maxMentions = 10
|
||||
|
@ -675,6 +678,7 @@ def createServerBob(path: str, domain: str, port: int,
|
|||
testSubject, testSchedulePost,
|
||||
testEventDate, testEventTime, testLocation,
|
||||
testIsArticle, systemLanguage)
|
||||
regenerateIndexForBox(path, nickname, domain, 'outbox')
|
||||
global testServerBobRunning
|
||||
testServerBobRunning = True
|
||||
maxMentions = 10
|
||||
|
@ -1343,7 +1347,7 @@ def testGroupFollow():
|
|||
aliceDomain = '127.0.0.57'
|
||||
alicePort = 61927
|
||||
aliceSendThreads = []
|
||||
# aliceAddress = aliceDomain + ':' + str(alicePort)
|
||||
aliceAddress = aliceDomain + ':' + str(alicePort)
|
||||
|
||||
bobDir = baseDir + '/.tests/bob'
|
||||
bobDomain = '127.0.0.59'
|
||||
|
@ -1368,7 +1372,7 @@ def testGroupFollow():
|
|||
threadWithTrace(target=createServerAlice,
|
||||
args=(aliceDir, aliceDomain, alicePort,
|
||||
testgroupAddress,
|
||||
federationList, False, False,
|
||||
federationList, False, True,
|
||||
aliceSendThreads),
|
||||
daemon=True)
|
||||
|
||||
|
@ -1422,6 +1426,35 @@ def testGroupFollow():
|
|||
assert ctr <= 60
|
||||
time.sleep(1)
|
||||
|
||||
print('*********************************************************')
|
||||
print('Alice has some outbox posts')
|
||||
aliceOutbox = 'http://' + aliceAddress + '/users/alice/outbox'
|
||||
session = createSession(None)
|
||||
profileStr = 'https://www.w3.org/ns/activitystreams'
|
||||
asHeader = {
|
||||
'Accept': 'application/ld+json; profile="' + profileStr + '"'
|
||||
}
|
||||
outboxJson = getJson(session, aliceOutbox, asHeader, None,
|
||||
True, __version__, 'http', None)
|
||||
assert outboxJson
|
||||
pprint(outboxJson)
|
||||
assert outboxJson['type'] == 'OrderedCollection'
|
||||
assert 'first' in outboxJson
|
||||
firstPage = outboxJson['first']
|
||||
assert 'totalItems' in outboxJson
|
||||
print('Alice outbox totalItems: ' + str(outboxJson['totalItems']))
|
||||
assert outboxJson['totalItems'] == 3
|
||||
|
||||
outboxJson = getJson(session, firstPage, asHeader, None,
|
||||
True, __version__, 'http', None)
|
||||
assert outboxJson
|
||||
pprint(outboxJson)
|
||||
assert 'orderedItems' in outboxJson
|
||||
assert outboxJson['type'] == 'OrderedCollectionPage'
|
||||
print('Alice outbox orderedItems: ' +
|
||||
str(len(outboxJson['orderedItems'])))
|
||||
assert len(outboxJson['orderedItems']) == 3
|
||||
|
||||
queuePath = \
|
||||
testgroupDir + '/accounts/testgroup@' + testgroupDomain + '/queue'
|
||||
|
||||
|
@ -1618,6 +1651,7 @@ def testGroupFollow():
|
|||
assert aliceMessageArrived is True
|
||||
print('\n\n*********************************************************')
|
||||
print('Post from Alice to test group succeeded')
|
||||
|
||||
print('\n\n*********************************************************')
|
||||
print('Check that post was relayed from test group to bob')
|
||||
|
||||
|
@ -4267,6 +4301,7 @@ def _testRemovePostInteractions() -> None:
|
|||
assert postJsonObject['object']['shares'] == {}
|
||||
assert postJsonObject['object']['bookmarks'] == {}
|
||||
assert postJsonObject['object']['ignores'] == {}
|
||||
postJsonObject['object']['to'] = ["some private address"]
|
||||
assert not removePostInteractions(postJsonObject, False)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue