Fix removals from moderation index

main
Bob Mottram 2019-11-16 22:09:54 +00:00
parent cb97b5ceb2
commit 26d561d4d7
2 changed files with 34 additions and 31 deletions

View File

@ -1001,31 +1001,31 @@ def createReportPost(baseDir: str,
postCc=None postCc=None
postJsonObject=None postJsonObject=None
for toUrl in postTo: for toUrl in postTo:
postJsonObject= \
createPostBase(baseDir,nickname, domain, port, \
toUrl,postCc, \
httpPrefix, content, followersOnly, saveToFile, \
clientToServer, \
attachImageFilename,mediaType, \
imageDescription,useBlurhash, \
True,None, None, subject, \
None,None,None)
if not postJsonObject:
continue
# who is this report going to? # who is this report going to?
toNickname=toUrl.split('/users/')[1] toNickname=toUrl.split('/users/')[1]
handle=toNickname+'@'+domain handle=toNickname+'@'+domain
postJsonObject= \
createPostBase(baseDir,nickname,domain,port, \
toUrl,postCc, \
httpPrefix,content,followersOnly,saveToFile, \
clientToServer, \
attachImageFilename,mediaType, \
imageDescription,useBlurhash, \
True,None,None,subject, \
None,None,None)
if not postJsonObject:
continue
# update the inbox index with the report filename # update the inbox index with the report filename
indexFilename=baseDir+'/accounts/'+handle+'/inbox.index' #indexFilename=baseDir+'/accounts/'+handle+'/inbox.index'
indexEntry=postJsonObject['id'].replace('/activity','').replace('/','#')+'.json' #indexEntry=postJsonObject['id'].replace('/activity','').replace('/','#')+'.json'
if indexEntry not in open(indexFilename).read(): #if indexEntry not in open(indexFilename).read():
try: # try:
with open(indexFilename, 'a+') as fp: # with open(indexFilename, 'a+') as fp:
fp.write(indexEntry) # fp.write(indexEntry)
except: # except:
pass # pass
# save a notification file so that the moderator # save a notification file so that the moderator
# knows something new has appeared # knows something new has appeared
@ -1820,7 +1820,7 @@ def createModeration(baseDir: str,nickname: str,domain: str,port: int,httpPrefix
if not pageNumber: if not pageNumber:
pageNumber=1 pageNumber=1
pageStr='?page='+str(pageNumber) pageStr='?page='+str(pageNumber)
boxHeader = {'@context': 'https://www.w3.org/ns/activitystreams', boxHeader = {'@context': 'https://www.w3.org/ns/activitystreams',
'first': httpPrefix+'://'+domain+'/users/'+nickname+'/'+boxname+'?page=true', 'first': httpPrefix+'://'+domain+'/users/'+nickname+'/'+boxname+'?page=true',
@ -1856,7 +1856,7 @@ def createModeration(baseDir: str,nickname: str,domain: str,port: int,httpPrefix
while lineNumber>=endLineNumber: while lineNumber>=endLineNumber:
pageLines.append(lines[lineNumber].strip('\n')) pageLines.append(lines[lineNumber].strip('\n'))
lineNumber-=1 lineNumber-=1
for postUrl in pageLines: for postUrl in pageLines:
postFilename=boxDir+'/'+postUrl.replace('/','#')+'.json' postFilename=boxDir+'/'+postUrl.replace('/','#')+'.json'
if os.path.isfile(postFilename): if os.path.isfile(postFilename):

View File

@ -314,19 +314,22 @@ def deletePost(baseDir: str,httpPrefix: str,nickname: str,domain: str,postFilena
if postJsonObject: if postJsonObject:
# remove any attachment # remove any attachment
removeAttachment(baseDir,httpPrefix,domain,postJsonObject) removeAttachment(baseDir,httpPrefix,domain,postJsonObject)
hasObject=False
if postJsonObject.get('object'):
hasObject=True
# remove from moderation index file # remove from moderation index file
if postJsonObject.get('moderationStatus'): if hasObject:
if postJsonObject.get('object'): if postJsonObject['object'].get('moderationStatus'):
if isinstance(postJsonObject['object'], dict): if postJsonObject.get('id'):
if postJsonObject['object'].get('id'): postId=postJsonObject['id'].replace('/activity','')
postId=postJsonObject['object']['id'].replace('/activity','') removeModerationPostFromIndex(baseDir,postId,debug)
removeModerationPostFromIndex(baseDir,postId,debug)
# remove any hashtags index entries # remove any hashtags index entries
removeHashtagIndex=False removeHashtagIndex=False
if postJsonObject.get('object'): if hasObject:
if isinstance(postJsonObject['object'], dict): if hasObject and isinstance(postJsonObject['object'], dict):
if postJsonObject['object'].get('content'): if postJsonObject['object'].get('content'):
if '#' in postJsonObject['object']['content']: if '#' in postJsonObject['object']['content']:
removeHashtagIndex=True removeHashtagIndex=True