main2
Bob Mottram 2019-10-06 10:48:37 +01:00
parent 193ac8916c
commit 9ed20c111e
1 changed files with 23 additions and 7 deletions

View File

@ -26,28 +26,44 @@ from auth import createBasicAuthHeader
from auth import createPassword
from session import postJson
def removeFromFollowRequests(baseDir: str, \
nickname: str,domain: str, \
denyHandle: str):
"""Removes a handle from follow requests
def removeFromFollowBase(baseDir: str, \
nickname: str,domain: str, \
acceptOrDenyHandle: str,followFile: str) -> None:
"""Removes a handle from follow requests or rejects file
"""
handle=nickname+'@'+domain
accountsDir=baseDir+'/accounts/'+handle
approveFollowsFilename=accountsDir+'/followrequests.txt'
approveFollowsFilename=accountsDir+'/'+followFile+'.txt'
if not os.path.isfile(approveFollowsFilename):
if debug:
print('WARN: Follow requests file '+approveFollowsFilename+' not found')
return
if denyHandle not in open(approveFollowsFilename).read():
if acceptOrDenyHandle not in open(approveFollowsFilename).read():
return
approvefilenew = open(approveFollowsFilename+'.new', 'w+')
with open(approveFollowsFilename, 'r') as approvefile:
for approveHandle in approvefile:
if not approveHandle.startswith(denyHandle):
if not approveHandle.startswith(acceptOrDenyHandle):
approvefilenew.write(approveHandle)
approvefilenew.close()
os.rename(approveFollowsFilename+'.new',approveFollowsFilename)
def removeFromFollowRequests(baseDir: str, \
nickname: str,domain: str, \
denyHandle: str) -> None:
"""Removes a handle from follow requests
"""
removeFromFollowBase(baseDir,nickname,domain, \
denyHandle,'followrequests')
def removeFromFollowRejects(baseDir: str, \
nickname: str,domain: str, \
acceptHandle: str) -> None:
"""Removes a handle from follow rejects
"""
removeFromFollowBase(baseDir,nickname,domain, \
acceptHandle,'followrejects')
def isFollowingActor(baseDir: str,nickname: str,domain: str,actor: str) -> bool:
"""Is the given actor a follower of the given nickname?
"""