If an instance has no shared inbox then send posts to individual inboxes

master
Bob Mottram 2019-08-26 18:42:06 +01:00
parent 5b6e8ef9a2
commit cb5594d0ca
2 changed files with 62 additions and 27 deletions

View File

@ -840,7 +840,7 @@ if args.actor:
print('Unable to webfinger '+nickname+'@'+domain) print('Unable to webfinger '+nickname+'@'+domain)
sys.exit() sys.exit()
asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'} asHeader = {'Accept': 'application/activity+json; profile="https://www.w3.org/ns/activitystreams"'}
personUrl = getUserUrl(wfRequest) personUrl = getUserUrl(wfRequest)
if nickname==domain: if nickname==domain:
personUrl=personUrl.replace('/users/','/actor/') personUrl=personUrl.replace('/users/','/actor/')

View File

@ -1431,6 +1431,15 @@ def sendToNamedAddresses(session,baseDir: str, \
sendThreads,postLog,cachedWebfingers, \ sendThreads,postLog,cachedWebfingers, \
personCache,debug,projectVersion) personCache,debug,projectVersion)
def hasSharedInbox(session,httpPrefix: str,domain: str) -> bool:
"""Returns true if the given domain has a shared inbox
"""
wfRequest=webfingerHandle(session,domain+'@'+domain,httpPrefix,{}, \
None,__version__)
if wfRequest:
return True
return False
def sendToFollowers(session,baseDir: str, \ def sendToFollowers(session,baseDir: str, \
nickname: str, domain: str, port: int, \ nickname: str, domain: str, port: int, \
httpPrefix: str,federationList: [], \ httpPrefix: str,federationList: [], \
@ -1467,19 +1476,30 @@ def sendToFollowers(session,baseDir: str, \
if debug: if debug:
print('DEBUG: follower handles for '+followerDomain) print('DEBUG: follower handles for '+followerDomain)
pprint(followerHandles) pprint(followerHandles)
withSharedInbox=hasSharedInbox(session,httpPrefix,followerDomain)
if debug:
if postToSharedInbox:
print(followerDomain+' has shared inbox')
else:
print(followerDomain+' does not have a shared inbox')
toPort=port toPort=port
index=0 index=0
toDomain=followerHandles[index].split('@')[1] toDomain=followerHandles[index].split('@')[1]
if ':' in toDomain: if ':' in toDomain:
toPort=toDomain.split(':')[1] toPort=toDomain.split(':')[1]
toDomain=toDomain.split(':')[0] toDomain=toDomain.split(':')[0]
toNickname=followerHandles[index].split('@')[0]
cc=''
if len(followerHandles)>1:
toNickname='inbox'
#nickname='inbox'
# If this is a profile update then send to shared inbox # If this is a profile update then send to shared inbox
cc=''
if withSharedInbox:
toNickname=followerHandles[index].split('@')[0]
# if there are more than one followers on the domain
# then send the post to the shared inbox
if len(followerHandles)>1:
toNickname='inbox'
if toNickname!='inbox' and postJsonObject.get('type'): if toNickname!='inbox' and postJsonObject.get('type'):
if postJsonObject['type']=='Update': if postJsonObject['type']=='Update':
if postJsonObject.get('object'): if postJsonObject.get('object'):
@ -1500,6 +1520,21 @@ def sendToFollowers(session,baseDir: str, \
federationList, \ federationList, \
sendThreads,postLog,cachedWebfingers, \ sendThreads,postLog,cachedWebfingers, \
personCache,debug,projectVersion) personCache,debug,projectVersion)
else:
# send to individual followers without using a shared inbox
for handle in followerHandles:
toNickname=handle.split('@')[0]
if debug:
print('DEBUG: Sending from '+nickname+'@'+domain+' to '+toNickname+'@'+toDomain)
sendSignedJson(postJsonObject,session,baseDir, \
nickname,domain,port, \
toNickname,toDomain,toPort, \
cc,httpPrefix,True,clientToServer, \
federationList, \
sendThreads,postLog,cachedWebfingers, \
personCache,debug,projectVersion)
if debug: if debug:
print('DEBUG: End of sendToFollowers') print('DEBUG: End of sendToFollowers')