diff --git a/acceptreject.py b/acceptreject.py index ff855312..6d4c4acd 100644 --- a/acceptreject.py +++ b/acceptreject.py @@ -156,6 +156,17 @@ def acceptFollow(baseDir: str,domain : str,messageJson: {}, \ nickname,acceptedDomainFull, \ messageJson['capabilities']) + # has this person already been unfollowed? + unfollowedFilename=baseDir+'/accounts/'+nickname+'@'+acceptedDomainFull+'/unfollowed.txt' + if os.path.isfile(unfollowedFilename): + if followedNickname+'@'+followedDomainFull in open(unfollowedFilename).read(): + if debug: + print('DEBUG: follow accept arrived for '+ \ + nickname+'@'+acceptedDomainFull+ \ + ' from '+followedNickname+'@'+followedDomainFull+ \ + ' but they have been unfollowed') + return + if followPerson(baseDir, \ nickname,acceptedDomainFull, \ followedNickname,followedDomainFull, \ diff --git a/follow.py b/follow.py index ed5c448c..ab314129 100644 --- a/follow.py +++ b/follow.py @@ -184,6 +184,7 @@ def unfollowPerson(baseDir: str,nickname: str, domain: str, \ os.mkdir(baseDir+'/accounts') if not os.path.isdir(baseDir+'/accounts/'+handle): os.mkdir(baseDir+'/accounts/'+handle) + filename=baseDir+'/accounts/'+handle+'/'+followFile if not os.path.isfile(filename): if debug: @@ -199,6 +200,18 @@ def unfollowPerson(baseDir: str,nickname: str, domain: str, \ for line in lines: if line.strip("\n") != handleToUnfollow: f.write(line) + + # write to an unfollowed file so that if a follow accept + # later arrives then it can be ignored + unfollowedFilename=baseDir+'/accounts/'+handle+'/unfollowed.txt' + if os.path.isfile(unfollowedFilename): + if handleToUnfollow not in open(unfollowedFilename).read(): + with open(filename, "a+") as f: + f.write(handleToUnfollow+'\n') + else: + with open(filename, "w+") as f: + f.write(handleToUnfollow+'\n') + return True def unfollowerOfPerson(baseDir: str,nickname: str,domain: str, \ diff --git a/utils.py b/utils.py index d4285000..d228253d 100644 --- a/utils.py +++ b/utils.py @@ -214,6 +214,21 @@ def followPerson(baseDir: str,nickname: str, domain: str, \ handleToFollow=followNickname+'@'+followDomain.split(':')[0].lower() else: handleToFollow=followNickname+'@'+followDomain.lower() + + # was this person previously unfollowed? + unfollowedFilename=baseDir+'/accounts/'+handle+'/unfollowed.txt' + if os.path.isfile(unfollowedFilename): + if handleToFollow in open(unfollowedFilename).read(): + # remove them from the unfollowed file + newLines='' + with open(unfollowedFilename, "r") as f: + lines = f.readlines() + for line in lines: + if handleToFollow not in line: + newLines+=line + with open(unfollowedFilename, "w") as f: + f.write(newLines) + if not os.path.isdir(baseDir+'/accounts'): os.mkdir(baseDir+'/accounts') if not os.path.isdir(baseDir+'/accounts/'+handle):