Return capability id and account

master
Bob Mottram 2019-07-08 18:15:55 +01:00
parent 77e2ec39bc
commit 08fdf5fa0a
2 changed files with 21 additions and 10 deletions

View File

@ -7,6 +7,7 @@ __email__ = "bob@freedombone.net"
__status__ = "Production"
import json
import commentjson
from pprint import pprint
import os
import sys
@ -351,15 +352,18 @@ def sendFollowRequest(session,baseDir: str, \
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
and if it's addressed to followers then we need to get a list of those.
This returns a list of account handles which follow the given actor
and also the corresponding capability id if it exists
"""
result=[]
if ':' not in actor:
return result
httpPrefix=actor.split(':')[0]
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
@ -367,12 +371,18 @@ def getFollowersOfActor(baseDir :str,actor :str) -> []:
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)
if actorHandle in open(followingFilename).read():
ocapFilename=baseDir+'/accounts/'+account+'/ocap/granted/'+httpPrefix+':##'+domain+':'+str(port)+'#users#'+nickname+'.json'
if os.path.isfile(ocapFilename):
with open(ocapFilename, 'r') as fp:
ocapJson=commentjson.load(fp)
if ocapJson.get('id'):
result.append([account,ocapJson['id']])
else:
result.append([account,None])
else:
result.append([account,None])
return result

View File

@ -362,9 +362,10 @@ def testFollowBetweenServers():
time.sleep(1)
actorFollows=getFollowersOfActor(aliceDir,httpPrefix+'://'+bobDomain+':'+str(bobPort)+'/users/bob')
print(str(actorFollows))
assert len(actorFollows)==1
print("actorFollows: "+actorFollows[0])
assert actorFollows[0]=='alice@'+aliceDomain
assert actorFollows[0][0]=='alice@'+aliceDomain
assert actorFollows[0][1].startswith(httpPrefix+'://'+bobDomain+':'+str(bobPort)+'/caps/')
print('\n\nEve tries to send to Bob')
sessionEve = createSession(eveDomain,evePort,useTor)