From 26d561d4d7d19b7e38d21335a88afbf1db647168 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 16 Nov 2019 22:09:54 +0000 Subject: [PATCH] Fix removals from moderation index --- posts.py | 44 ++++++++++++++++++++++---------------------- utils.py | 21 ++++++++++++--------- 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/posts.py b/posts.py index 59c6fd41..d98b3434 100644 --- a/posts.py +++ b/posts.py @@ -1001,31 +1001,31 @@ def createReportPost(baseDir: str, postCc=None postJsonObject=None 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? toNickname=toUrl.split('/users/')[1] 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 - indexFilename=baseDir+'/accounts/'+handle+'/inbox.index' - indexEntry=postJsonObject['id'].replace('/activity','').replace('/','#')+'.json' - if indexEntry not in open(indexFilename).read(): - try: - with open(indexFilename, 'a+') as fp: - fp.write(indexEntry) - except: - pass + #indexFilename=baseDir+'/accounts/'+handle+'/inbox.index' + #indexEntry=postJsonObject['id'].replace('/activity','').replace('/','#')+'.json' + #if indexEntry not in open(indexFilename).read(): + # try: + # with open(indexFilename, 'a+') as fp: + # fp.write(indexEntry) + # except: + # pass # save a notification file so that the moderator # knows something new has appeared @@ -1820,7 +1820,7 @@ def createModeration(baseDir: str,nickname: str,domain: str,port: int,httpPrefix if not pageNumber: pageNumber=1 - + pageStr='?page='+str(pageNumber) boxHeader = {'@context': 'https://www.w3.org/ns/activitystreams', '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: pageLines.append(lines[lineNumber].strip('\n')) lineNumber-=1 - + for postUrl in pageLines: postFilename=boxDir+'/'+postUrl.replace('/','#')+'.json' if os.path.isfile(postFilename): diff --git a/utils.py b/utils.py index 17d03e02..5c7ea571 100644 --- a/utils.py +++ b/utils.py @@ -314,19 +314,22 @@ def deletePost(baseDir: str,httpPrefix: str,nickname: str,domain: str,postFilena if postJsonObject: # remove any attachment removeAttachment(baseDir,httpPrefix,domain,postJsonObject) - + + hasObject=False + if postJsonObject.get('object'): + hasObject=True + # remove from moderation index file - if postJsonObject.get('moderationStatus'): - if postJsonObject.get('object'): - if isinstance(postJsonObject['object'], dict): - if postJsonObject['object'].get('id'): - postId=postJsonObject['object']['id'].replace('/activity','') - removeModerationPostFromIndex(baseDir,postId,debug) + if hasObject: + if postJsonObject['object'].get('moderationStatus'): + if postJsonObject.get('id'): + postId=postJsonObject['id'].replace('/activity','') + removeModerationPostFromIndex(baseDir,postId,debug) # remove any hashtags index entries removeHashtagIndex=False - if postJsonObject.get('object'): - if isinstance(postJsonObject['object'], dict): + if hasObject: + if hasObject and isinstance(postJsonObject['object'], dict): if postJsonObject['object'].get('content'): if '#' in postJsonObject['object']['content']: removeHashtagIndex=True