diff --git a/follow.py b/follow.py index 686b608a6..ae34efe85 100644 --- a/follow.py +++ b/follow.py @@ -26,6 +26,28 @@ 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 + """ + handle=nickname+'@'+domain + accountsDir=baseDir+'/accounts/'+handle + approveFollowsFilename=accountsDir+'/followrequests.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(): + return + approvefilenew = open(approveFollowsFilename+'.new', 'w+') + with open(approveFollowsFilename, 'r') as approvefile: + for approveHandle in approvefile: + if not approveHandle.startswith(denyHandle): + approvefilenew.write(approveHandle) + approvefilenew.close() + os.rename(approveFollowsFilename+'.new',approveFollowsFilename) + def isFollowingActor(baseDir: str,nickname: str,domain: str,actor: str) -> bool: """Is the given actor a follower of the given nickname? """ @@ -442,6 +464,7 @@ def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \ denyHandle=nicknameToFollow+'@'+domainToFollowFull if denyHandle in open(rejectedFollowsFilename).read(): print(denyHandle+' was already denied as a follower of '+nickname) + removeFromFollowRequests(baseDir,nickname,domain,denyHandle) return True print('Storing follow request for approval') diff --git a/manualapprove.py b/manualapprove.py index f8d610402..6cf33d465 100644 --- a/manualapprove.py +++ b/manualapprove.py @@ -12,6 +12,7 @@ import commentjson from follow import followedAccountAccepts from follow import followedAccountRejects +from follow import removeFromFollowRequests def manualDenyFollowRequest(session,baseDir: str, \ httpPrefix: str, @@ -34,20 +35,7 @@ def manualDenyFollowRequest(session,baseDir: str, \ print(denyHandle+' has already been rejected as a follower of '+nickname) return - approveFollowsFilename=accountsDir+'/followrequests.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(): - return - approvefilenew = open(approveFollowsFilename+'.new', 'w+') - with open(approveFollowsFilename, 'r') as approvefile: - for approveHandle in approvefile: - if not approveHandle.startswith(denyHandle): - approvefilenew.write(approveHandle) - approvefilenew.close() - os.rename(approveFollowsFilename+'.new',approveFollowsFilename) + removeFromFollowRequests(baseDir,nickname,domain,denyHandle) # Store rejected follows rejectsFile=open(rejectedFollowsFilename, "a+")