From 79faa91534b0da1d5fbf3fad507f7f01e455e9ef Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 12 Mar 2021 10:44:37 +0000 Subject: [PATCH] Removing actors from follow request file --- follow.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/follow.py b/follow.py index 6c88c1adf..91f8ff9e0 100644 --- a/follow.py +++ b/follow.py @@ -84,7 +84,7 @@ def _removeFromFollowBase(baseDir: str, nickname: str, domain: str, acceptOrDenyHandle: str, followFile: str, debug: bool) -> None: - """Removes a handle from follow requests or rejects file + """Removes a handle/actor from follow requests or rejects file """ handle = nickname + '@' + domain accountsDir = baseDir + '/accounts/' + handle @@ -94,8 +94,26 @@ def _removeFromFollowBase(baseDir: str, print('WARN: Approve follow requests file ' + approveFollowsFilename + ' not found') return + acceptDenyActor = None if acceptOrDenyHandle not in open(approveFollowsFilename).read(): - return + # is this stored in the file as an actor rather than a handle? + acceptDenyNickname = acceptOrDenyHandle.split('@')[0] + acceptDenyDomain = acceptOrDenyHandle.split('@')[1] + # for each possible users path construct an actor and + # check if it exists in teh file + usersPaths = ('users', 'profile', 'channel', 'accounts', 'u') + actorFound = False + for usersName in usersPaths: + acceptDenyActor = \ + '://' + acceptDenyDomain + '/' + \ + usersName + '/' + acceptDenyNickname + if acceptDenyActor in open(approveFollowsFilename).read(): + # actor found, so use it in the subsequent removal + approveHandle = acceptDenyActor + actorFound = True + break + if not actorFound: + return approvefilenew = open(approveFollowsFilename + '.new', 'w+') with open(approveFollowsFilename, 'r') as approvefile: for approveHandle in approvefile: