When deleting a post also remove its replies

master
Bob Mottram 2019-07-14 15:42:00 +01:00
parent 20a5864a12
commit 3d6a363e6a
3 changed files with 36 additions and 1 deletions

View File

@ -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

View File

@ -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)

View File

@ -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,