diff --git a/follow.py b/follow.py index 3e809ea7..7b2488b8 100644 --- a/follow.py +++ b/follow.py @@ -36,22 +36,6 @@ def getFollowersOfPerson(baseDir: str,nickname: str,domain: str,followFile='foll break return followers -def noOfFollowersOnDomain(baseDir: str,handle: str, domain: str, followFile='followers.txt') -> int: - """Returns the number of followers of the given handle from the given domain - """ - filename=baseDir+'/accounts/'+handle+'/'+followFile - if not os.path.isfile(filename): - return 0 - - ctr=0 - with open(filename, "r") as followersFilename: - for followerHandle in followersFilename: - if '@' in followerHandle: - followerDomain=followerHandle.split('@')[1].replace('\n','') - if domain==followerDomain: - ctr+=1 - return ctr - def followPerson(baseDir: str,nickname: str, domain: str, \ followNickname: str, followDomain: str, \ federationList: [], followFile='following.txt') -> bool: diff --git a/posts.py b/posts.py index 9a481bdc..80f7307c 100644 --- a/posts.py +++ b/posts.py @@ -35,6 +35,22 @@ try: except ImportError: from bs4 import BeautifulSoup +def noOfFollowersOnDomain(baseDir: str,handle: str, domain: str, followFile='followers.txt') -> int: + """Returns the number of followers of the given handle from the given domain + """ + filename=baseDir+'/accounts/'+handle+'/'+followFile + if not os.path.isfile(filename): + return 0 + + ctr=0 + with open(filename, "r") as followersFilename: + for followerHandle in followersFilename: + if '@' in followerHandle: + followerDomain=followerHandle.split('@')[1].replace('\n','') + if domain==followerDomain: + ctr+=1 + return ctr + def getPersonKey(nickname: str,domain: str,baseDir: str,keyType='public'): """Returns the public or private key of a person """ @@ -456,6 +472,12 @@ def sendPost(session,baseDir: str,nickname: str, domain: str, port: int, \ # get the actor inbox for the To handle inboxUrl,pubKeyId,pubKey,toPersonId,sharedInbox = \ getPersonBox(session,wfRequest,personCache,'inbox') + + # If there are more than one followers on the target domain + # then send to teh shared inbox indead of the individual inbox + if noOfFollowersOnDomain(baseDir,handle,toDomain)>1 and sharedInbox: + inboxUrl=sharedInbox + if not inboxUrl: return 2 if not pubKey: diff --git a/tests.py b/tests.py index a66975f3..c67540a3 100644 --- a/tests.py +++ b/tests.py @@ -23,6 +23,7 @@ from posts import deleteAllPosts from posts import createPublicPost from posts import sendPost from posts import archivePosts +from posts import noOfFollowersOnDomain from follow import clearFollows from follow import clearFollowers from follow import followPerson @@ -30,7 +31,6 @@ from follow import followerOfPerson from follow import unfollowPerson from follow import unfollowerOfPerson from follow import getFollowersOfPerson -from follow import noOfFollowersOnDomain from person import createPerson from person import setPreferredNickname from person import setBio