From 3d6a363e6a54cda5ab0d6cd2b0de79a85fe2f3cc Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 14 Jul 2019 15:42:00 +0100 Subject: [PATCH] When deleting a post also remove its replies --- epicyon.py | 1 + inbox.py | 14 +++++++++++++- person.py | 22 ++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/epicyon.py b/epicyon.py index 27e1b1be..2259b636 100644 --- a/epicyon.py +++ b/epicyon.py @@ -17,6 +17,7 @@ from person import setProfileImage from person import setSkillLevel from person import setRole from person import setAvailability +from person import setOrganizationScheme from webfinger import webfingerHandle from posts import getPosts from posts import createPublicPost diff --git a/inbox.py b/inbox.py index 1baa9948..920c871e 100644 --- a/inbox.py +++ b/inbox.py @@ -533,7 +533,19 @@ def receiveDelete(session,handle: str,baseDir: str, \ if debug: print('DEBUG: delete post not found in inbox or outbox') print(messageJson['object']) - return True + return True + repliesFilename=postFilename.replace('.json','.replies') + if os.path.isfile(repliesFilename): + if debug: + print('DEBUG: removing replies to '+postFilename) + with open(repliesFilename,'r') as f: + for replyId in f: + replyFile=locatePost(baseDir,handle.split('@')[0],handle.split('@')[1],replyId) + if replyFile: + if os.path.isfile(replyFile): + os.remove(replyFile) + # remove the replies file itself + os.remove(repliesFilename) os.remove(postFilename) if debug: print('DEBUG: post deleted - '+postFilename) diff --git a/person.py b/person.py index 81b8277b..bad32e3d 100644 --- a/person.py +++ b/person.py @@ -137,6 +137,25 @@ def setRole(baseDir: str,nickname: str,domain: str, \ commentjson.dump(actorJson, fp, indent=4, sort_keys=False) return True +def setOrganizationScheme(baseDir: str,nickname: str,domain: str, \ + schema: str) -> bool: + """Set the organization schema within which a person exists + This will define how roles, skills and availability are assembled + into organizations + """ + # avoid giant strings + if len(schema)>256: + return False + actorFilename=baseDir+'/accounts/'+nickname+'@'+domain+'.json' + if not os.path.isfile(actorFilename): + return False + with open(actorFilename, 'r') as fp: + actorJson=commentjson.load(fp) + actorJson['orgSchema']=schema + with open(actorFilename, 'w') as fp: + commentjson.dump(actorJson, fp, indent=4, sort_keys=False) + return True + def setAvailability(baseDir: str,nickname: str,domain: str, \ status: str) -> bool: """Set an availability status @@ -150,6 +169,8 @@ def setAvailability(baseDir: str,nickname: str,domain: str, \ with open(actorFilename, 'r') as fp: actorJson=commentjson.load(fp) actorJson['availability']=status + with open(actorFilename, 'w') as fp: + commentjson.dump(actorJson, fp, indent=4, sort_keys=False) return True def createPersonBase(baseDir: str,nickname: str,domain: str,port: int, \ @@ -190,6 +211,7 @@ def createPersonBase(baseDir: str,nickname: str,domain: str,port: int, \ 'featured': httpPrefix+'://'+domain+'/users/'+nickname+'/collections/featured', 'followers': httpPrefix+'://'+domain+'/users/'+nickname+'/followers', 'following': httpPrefix+'://'+domain+'/users/'+nickname+'/following', + 'orgSchema': None, 'skills': {}, 'roles': {}, 'availability': None,