Fix removal of post interactions

merge-requests/26/head
Bob Mottram 2021-08-01 20:19:45 +01:00
parent 0be2e87ffa
commit 3469850199
3 changed files with 85 additions and 7 deletions

View File

@ -9214,7 +9214,7 @@ class PubServer(BaseHTTPRequestHandler):
proxyType: str, cookie: str, proxyType: str, cookie: str,
debug: str) -> bool: debug: str) -> bool:
"""Shows the outbox timeline """Shows the outbox timeline
""" """
# get outbox feed for a person # get outbox feed for a person
outboxFeed = \ outboxFeed = \
personBoxJson(self.server.recentPostsCache, personBoxJson(self.server.recentPostsCache,

View File

@ -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, def createPublicPost(baseDir: str,
nickname: str, domain: str, port: int, httpPrefix: str, nickname: str, domain: str, port: int, httpPrefix: str,
content: str, followersOnly: bool, saveToFile: bool, content: str, followersOnly: bool, saveToFile: bool,
@ -3164,7 +3195,7 @@ def removePostInteractions(postJsonObject: {}, force: bool) -> bool:
if not force: if not force:
# If not authorized and it's a private post # If not authorized and it's a private post
# then just don't show it within timelines # then just don't show it within timelines
if not isPublicPost(postObj): if not isPublicPost(postJsonObject):
return False return False
else: else:
postObj = postJsonObject postObj = postJsonObject
@ -3267,6 +3298,7 @@ def _createBoxIndexed(recentPostsCache: {},
indexBoxName = boxname indexBoxName = boxname
timelineNickname = 'news' timelineNickname = 'news'
originalDomain = domain
domain = getFullDomain(domain, port) domain = getFullDomain(domain, port)
boxActor = httpPrefix + '://' + domain + '/users/' + nickname boxActor = httpPrefix + '://' + domain + '/users/' + nickname
@ -3300,7 +3332,7 @@ def _createBoxIndexed(recentPostsCache: {},
postsInBox = [] postsInBox = []
indexFilename = \ indexFilename = \
baseDir + '/accounts/' + timelineNickname + '@' + domain + \ acctDir(baseDir, timelineNickname, originalDomain) + \
'/' + indexBoxName + '.index' '/' + indexBoxName + '.index'
totalPostsCount = 0 totalPostsCount = 0
postsAddedToTimeline = 0 postsAddedToTimeline = 0
@ -3342,22 +3374,29 @@ def _createBoxIndexed(recentPostsCache: {},
if postUrl in recentPostsCache['index']: if postUrl in recentPostsCache['index']:
if recentPostsCache['json'].get(postUrl): if recentPostsCache['json'].get(postUrl):
url = recentPostsCache['json'][postUrl] url = recentPostsCache['json'][postUrl]
print('Adding post to timeline: ' +
boxname + ' ' + url)
if _addPostStringToTimeline(url, if _addPostStringToTimeline(url,
boxname, postsInBox, boxname, postsInBox,
boxActor): boxActor):
totalPostsCount += 1 totalPostsCount += 1
postsAddedToTimeline += 1 postsAddedToTimeline += 1
continue continue
else:
print('Post not added to timeline')
print('postsInBox: ' + str(len(postsInBox)))
# read the post from file # read the post from file
fullPostFilename = \ fullPostFilename = \
locatePost(baseDir, nickname, locatePost(baseDir, nickname,
domain, postUrl, False) originalDomain, postUrl, False)
if fullPostFilename: if fullPostFilename:
# has the post been rejected? # has the post been rejected?
if os.path.isfile(fullPostFilename + '.reject'): if os.path.isfile(fullPostFilename + '.reject'):
continue continue
print('Adding post to timeline: ' +
boxname + ' ' + fullPostFilename)
if _addPostToTimeline(fullPostFilename, boxname, if _addPostToTimeline(fullPostFilename, boxname,
postsInBox, boxActor): postsInBox, boxActor):
postsAddedToTimeline += 1 postsAddedToTimeline += 1
@ -3366,13 +3405,16 @@ def _createBoxIndexed(recentPostsCache: {},
print('WARN: Unable to add post ' + postUrl + print('WARN: Unable to add post ' + postUrl +
' nickname ' + nickname + ' nickname ' + nickname +
' timeline ' + boxname) ' timeline ' + boxname)
print('postsInBox: ' + str(len(postsInBox)))
else: else:
if timelineNickname != nickname: if timelineNickname != nickname:
# if this is the features timeline # if this is the features timeline
fullPostFilename = \ fullPostFilename = \
locatePost(baseDir, timelineNickname, locatePost(baseDir, timelineNickname,
domain, postUrl, False) originalDomain, postUrl, False)
if fullPostFilename: if fullPostFilename:
print('Adding post to timeline: ' +
boxname + ' ' + fullPostFilename)
if _addPostToTimeline(fullPostFilename, boxname, if _addPostToTimeline(fullPostFilename, boxname,
postsInBox, boxActor): postsInBox, boxActor):
postsAddedToTimeline += 1 postsAddedToTimeline += 1
@ -3381,6 +3423,7 @@ def _createBoxIndexed(recentPostsCache: {},
print('WARN: Unable to add features post ' + print('WARN: Unable to add features post ' +
postUrl + ' nickname ' + nickname + postUrl + ' nickname ' + nickname +
' timeline ' + boxname) ' timeline ' + boxname)
print('postsInBox: ' + str(len(postsInBox)))
else: else:
print('WARN: features timeline. ' + print('WARN: features timeline. ' +
'Unable to locate post ' + postUrl) 'Unable to locate post ' + postUrl)

View File

@ -24,6 +24,8 @@ from cache import getPersonFromCache
from threads import threadWithTrace from threads import threadWithTrace
from daemon import runDaemon from daemon import runDaemon
from session import createSession from session import createSession
from session import getJson
from posts import regenerateIndexForBox
from posts import removePostInteractions from posts import removePostInteractions
from posts import getMentionedPeople from posts import getMentionedPeople
from posts import validContentWarning from posts import validContentWarning
@ -547,6 +549,7 @@ def createServerAlice(path: str, domain: str, port: int,
testSubject, testSchedulePost, testSubject, testSchedulePost,
testEventDate, testEventTime, testLocation, testEventDate, testEventTime, testLocation,
testIsArticle, systemLanguage) testIsArticle, systemLanguage)
regenerateIndexForBox(path, nickname, domain, 'outbox')
global testServerAliceRunning global testServerAliceRunning
testServerAliceRunning = True testServerAliceRunning = True
maxMentions = 10 maxMentions = 10
@ -675,6 +678,7 @@ def createServerBob(path: str, domain: str, port: int,
testSubject, testSchedulePost, testSubject, testSchedulePost,
testEventDate, testEventTime, testLocation, testEventDate, testEventTime, testLocation,
testIsArticle, systemLanguage) testIsArticle, systemLanguage)
regenerateIndexForBox(path, nickname, domain, 'outbox')
global testServerBobRunning global testServerBobRunning
testServerBobRunning = True testServerBobRunning = True
maxMentions = 10 maxMentions = 10
@ -1343,7 +1347,7 @@ def testGroupFollow():
aliceDomain = '127.0.0.57' aliceDomain = '127.0.0.57'
alicePort = 61927 alicePort = 61927
aliceSendThreads = [] aliceSendThreads = []
# aliceAddress = aliceDomain + ':' + str(alicePort) aliceAddress = aliceDomain + ':' + str(alicePort)
bobDir = baseDir + '/.tests/bob' bobDir = baseDir + '/.tests/bob'
bobDomain = '127.0.0.59' bobDomain = '127.0.0.59'
@ -1368,7 +1372,7 @@ def testGroupFollow():
threadWithTrace(target=createServerAlice, threadWithTrace(target=createServerAlice,
args=(aliceDir, aliceDomain, alicePort, args=(aliceDir, aliceDomain, alicePort,
testgroupAddress, testgroupAddress,
federationList, False, False, federationList, False, True,
aliceSendThreads), aliceSendThreads),
daemon=True) daemon=True)
@ -1422,6 +1426,35 @@ def testGroupFollow():
assert ctr <= 60 assert ctr <= 60
time.sleep(1) 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 = \ queuePath = \
testgroupDir + '/accounts/testgroup@' + testgroupDomain + '/queue' testgroupDir + '/accounts/testgroup@' + testgroupDomain + '/queue'
@ -1618,6 +1651,7 @@ def testGroupFollow():
assert aliceMessageArrived is True assert aliceMessageArrived is True
print('\n\n*********************************************************') print('\n\n*********************************************************')
print('Post from Alice to test group succeeded') print('Post from Alice to test group succeeded')
print('\n\n*********************************************************') print('\n\n*********************************************************')
print('Check that post was relayed from test group to bob') 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']['shares'] == {}
assert postJsonObject['object']['bookmarks'] == {} assert postJsonObject['object']['bookmarks'] == {}
assert postJsonObject['object']['ignores'] == {} assert postJsonObject['object']['ignores'] == {}
postJsonObject['object']['to'] = ["some private address"]
assert not removePostInteractions(postJsonObject, False) assert not removePostInteractions(postJsonObject, False)