forked from indymedia/epicyon
Function for getting the followers of an actor
parent
db68b34cc5
commit
77e2ec39bc
28
follow.py
28
follow.py
|
@ -348,3 +348,31 @@ def sendFollowRequest(session,baseDir: str, \
|
||||||
sendThreads,postLog,cachedWebfingers,personCache, debug)
|
sendThreads,postLog,cachedWebfingers,personCache, debug)
|
||||||
|
|
||||||
return newFollowJson
|
return newFollowJson
|
||||||
|
|
||||||
|
def getFollowersOfActor(baseDir :str,actor :str) -> []:
|
||||||
|
"""In a shared inbox if we receive a post we know who it's from
|
||||||
|
and if it's addressed to followers then we need to get a list of those
|
||||||
|
"""
|
||||||
|
result=[]
|
||||||
|
nickname=getNicknameFromActor(actor)
|
||||||
|
print("nickname: "+nickname)
|
||||||
|
if not nickname:
|
||||||
|
return result
|
||||||
|
domain,port=getDomainFromActor(actor)
|
||||||
|
print("domain: "+domain)
|
||||||
|
if not domain:
|
||||||
|
return result
|
||||||
|
actorHandle=nickname+'@'+domain
|
||||||
|
# for each of the accounts
|
||||||
|
for subdir, dirs, files in os.walk(baseDir+'/accounts'):
|
||||||
|
for account in dirs:
|
||||||
|
if '@' in account and not account.startswith('inbox@'):
|
||||||
|
print("account: "+account)
|
||||||
|
followingFilename = os.path.join(subdir, account)+'/following.txt'
|
||||||
|
if os.path.isfile(followingFilename):
|
||||||
|
print("followingFilename: "+followingFilename)
|
||||||
|
print("actorHandle: "+actorHandle)
|
||||||
|
# does this account follow the given actor?
|
||||||
|
if actorHandle in open(followingFilename).read():
|
||||||
|
result.append(account)
|
||||||
|
return result
|
||||||
|
|
6
tests.py
6
tests.py
|
@ -33,6 +33,7 @@ from follow import unfollowPerson
|
||||||
from follow import unfollowerOfPerson
|
from follow import unfollowerOfPerson
|
||||||
from follow import getFollowersOfPerson
|
from follow import getFollowersOfPerson
|
||||||
from follow import sendFollowRequest
|
from follow import sendFollowRequest
|
||||||
|
from follow import getFollowersOfActor
|
||||||
from person import createPerson
|
from person import createPerson
|
||||||
from person import setPreferredNickname
|
from person import setPreferredNickname
|
||||||
from person import setBio
|
from person import setBio
|
||||||
|
@ -360,6 +361,11 @@ def testFollowBetweenServers():
|
||||||
break
|
break
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
actorFollows=getFollowersOfActor(aliceDir,httpPrefix+'://'+bobDomain+':'+str(bobPort)+'/users/bob')
|
||||||
|
assert len(actorFollows)==1
|
||||||
|
print("actorFollows: "+actorFollows[0])
|
||||||
|
assert actorFollows[0]=='alice@'+aliceDomain
|
||||||
|
|
||||||
print('\n\nEve tries to send to Bob')
|
print('\n\nEve tries to send to Bob')
|
||||||
sessionEve = createSession(eveDomain,evePort,useTor)
|
sessionEve = createSession(eveDomain,evePort,useTor)
|
||||||
eveSendThreads = []
|
eveSendThreads = []
|
||||||
|
|
Loading…
Reference in New Issue