forked from indymedia/epicyon
Add unfollowed file
This prevents received follow accepts from refollowing after an unfollowmain
parent
373c65a103
commit
4db44418be
|
@ -156,6 +156,17 @@ def acceptFollow(baseDir: str,domain : str,messageJson: {}, \
|
||||||
nickname,acceptedDomainFull, \
|
nickname,acceptedDomainFull, \
|
||||||
messageJson['capabilities'])
|
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, \
|
if followPerson(baseDir, \
|
||||||
nickname,acceptedDomainFull, \
|
nickname,acceptedDomainFull, \
|
||||||
followedNickname,followedDomainFull, \
|
followedNickname,followedDomainFull, \
|
||||||
|
|
13
follow.py
13
follow.py
|
@ -184,6 +184,7 @@ def unfollowPerson(baseDir: str,nickname: str, domain: str, \
|
||||||
os.mkdir(baseDir+'/accounts')
|
os.mkdir(baseDir+'/accounts')
|
||||||
if not os.path.isdir(baseDir+'/accounts/'+handle):
|
if not os.path.isdir(baseDir+'/accounts/'+handle):
|
||||||
os.mkdir(baseDir+'/accounts/'+handle)
|
os.mkdir(baseDir+'/accounts/'+handle)
|
||||||
|
|
||||||
filename=baseDir+'/accounts/'+handle+'/'+followFile
|
filename=baseDir+'/accounts/'+handle+'/'+followFile
|
||||||
if not os.path.isfile(filename):
|
if not os.path.isfile(filename):
|
||||||
if debug:
|
if debug:
|
||||||
|
@ -199,6 +200,18 @@ def unfollowPerson(baseDir: str,nickname: str, domain: str, \
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if line.strip("\n") != handleToUnfollow:
|
if line.strip("\n") != handleToUnfollow:
|
||||||
f.write(line)
|
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
|
return True
|
||||||
|
|
||||||
def unfollowerOfPerson(baseDir: str,nickname: str,domain: str, \
|
def unfollowerOfPerson(baseDir: str,nickname: str,domain: str, \
|
||||||
|
|
15
utils.py
15
utils.py
|
@ -214,6 +214,21 @@ def followPerson(baseDir: str,nickname: str, domain: str, \
|
||||||
handleToFollow=followNickname+'@'+followDomain.split(':')[0].lower()
|
handleToFollow=followNickname+'@'+followDomain.split(':')[0].lower()
|
||||||
else:
|
else:
|
||||||
handleToFollow=followNickname+'@'+followDomain.lower()
|
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'):
|
if not os.path.isdir(baseDir+'/accounts'):
|
||||||
os.mkdir(baseDir+'/accounts')
|
os.mkdir(baseDir+'/accounts')
|
||||||
if not os.path.isdir(baseDir+'/accounts/'+handle):
|
if not os.path.isdir(baseDir+'/accounts/'+handle):
|
||||||
|
|
Loading…
Reference in New Issue