diff --git a/follow.py b/follow.py index dc917cd29..cbcd07ed6 100644 --- a/follow.py +++ b/follow.py @@ -278,7 +278,12 @@ def getNoOfFollows(baseDir: str, nickname: str, domain: str, '.' in line and \ not line.startswith('http'): ctr += 1 - elif line.startswith('http') and '/users/' in line: + elif ((line.startswith('http') or + line.startswith('dat')) and + ('/users/' in line or + '/profile/' in line or + '/accounts/' in line or + '/channel/' in line)): ctr += 1 return ctr @@ -487,7 +492,7 @@ def storeFollowRequest(baseDir: str, nicknameToFollow: str, domainToFollow: str, port: int, nickname: str, domain: str, fromPort: int, followJson: {}, - debug: bool) -> bool: + debug: bool, personUrl: str) -> bool: """Stores the follow request for later use """ accountsDir = baseDir + '/accounts/' + \ @@ -539,17 +544,23 @@ def storeFollowRequest(baseDir: str, # add to a file which contains a list of requests approveFollowsFilename = accountsDir + '/followrequests.txt' + + # store either nick@domain or the full person/actor url + approveHandleStored = approveHandle + if '/users/' not in personUrl: + approveHandleStored = personUrl + if os.path.isfile(approveFollowsFilename): if approveHandle not in open(approveFollowsFilename).read(): with open(approveFollowsFilename, 'a+') as fp: - fp.write(approveHandle + '\n') + fp.write(approveHandleStored + '\n') else: if debug: - print('DEBUG: ' + approveHandle + + print('DEBUG: ' + approveHandleStored + ' is already awaiting approval') else: with open(approveFollowsFilename, "w+") as fp: - fp.write(approveHandle + '\n') + fp.write(approveHandleStored + '\n') # store the follow request in its own directory # We don't rely upon the inbox because items in there could expire @@ -690,7 +701,7 @@ def receiveFollowRequest(session, baseDir: str, httpPrefix: str, return storeFollowRequest(baseDir, nicknameToFollow, domainToFollow, port, nickname, domain, fromPort, - messageJson, debug) + messageJson, debug, messageJson['actor']) else: print('Follow request does not require approval') # update the followers diff --git a/manualapprove.py b/manualapprove.py index b4252bc6a..5bb3c3be8 100644 --- a/manualapprove.py +++ b/manualapprove.py @@ -98,8 +98,29 @@ def manualApproveFollowRequest(session, baseDir: str, print('Manual follow accept: follow requests file ' + approveFollowsFilename + ' not found') return + # is the handle in the requests file? - if approveHandle not in open(approveFollowsFilename).read(): + approveFollowsStr = '' + with open(approveFollowsFilename, 'r') as fpFollowers: + approveFollowsStr = fpFollowers.read() + exists = True + approveHandleFull = approveHandle + if approveHandle not in approveFollowsStr: + exists = False + elif '@' in approveHandle: + reqNick = approveHandle.split('@')[0] + reqDomain = approveHandle.split('@')[1].strip() + reqPrefix = httpPrefix + '://' + reqDomain + if reqPrefix + '/profile/' + reqNick not in approveFollowsStr: + exists = False + approveHandleFull = reqPrefix + '/profile/' + reqNick + elif reqPrefix + '/channel/' + reqNick not in approveFollowsStr: + exists = False + approveHandleFull = reqPrefix + '/channel/' + reqNick + elif reqPrefix + '/accounts/' + reqNick not in approveFollowsStr: + exists = False + approveHandleFull = reqPrefix + '/accounts/' + reqNick + if not exists: print('Manual follow accept: ' + approveHandle + ' not in requests file ' + approveFollowsFilename) return @@ -157,28 +178,28 @@ def manualApproveFollowRequest(session, baseDir: str, # update the followers print('Manual follow accept: updating ' + followersFilename) if os.path.isfile(followersFilename): - if approveHandle not in open(followersFilename).read(): + if approveHandleFull not in open(followersFilename).read(): try: with open(followersFilename, 'r+') as followersFile: content = followersFile.read() followersFile.seek(0, 0) - followersFile.write(approveHandle + '\n' + content) + followersFile.write(approveHandleFull + '\n' + content) except Exception as e: print('WARN: Manual follow accept. ' + 'Failed to write entry to followers file ' + str(e)) else: - print('WARN: Manual follow accept: ' + approveHandle + + print('WARN: Manual follow accept: ' + approveHandleFull + ' already exists in ' + followersFilename) else: print('Manual follow accept: first follower accepted for ' + - handle + ' is ' + approveHandle) + handle + ' is ' + approveHandleFull) followersFile = open(followersFilename, "w+") - followersFile.write(approveHandle + '\n') + followersFile.write(approveHandleFull + '\n') followersFile.close() # only update the follow requests file if the follow is confirmed to be # in followers.txt - if approveHandle in open(followersFilename).read(): + if approveHandleFull in open(followersFilename).read(): # mark this handle as approved for following approveFollowerHandle(accountDir, approveHandle) # update the follow requests with the handles not yet approved