Function for getting the followers of an actor

master
Bob Mottram 2019-07-08 17:49:12 +01:00
parent db68b34cc5
commit 77e2ec39bc
2 changed files with 34 additions and 0 deletions

View File

@ -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

View File

@ -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 = []