mirror of https://gitlab.com/bashrc2/epicyon
				
				
				
			If an instance has no shared inbox then send posts to individual inboxes
							parent
							
								
									5b6e8ef9a2
								
							
						
					
					
						commit
						cb5594d0ca
					
				|  | @ -833,14 +833,14 @@ if args.actor: | ||||||
|     session=createSession(domain,port,useTor) |     session=createSession(domain,port,useTor) | ||||||
|     if nickname=='inbox': |     if nickname=='inbox': | ||||||
|         nickname=domain |         nickname=domain | ||||||
|          | 
 | ||||||
|     wfRequest=webfingerHandle(session,nickname+'@'+domain,httpPrefix,wfCache, \ |     wfRequest=webfingerHandle(session,nickname+'@'+domain,httpPrefix,wfCache, \ | ||||||
|                               None,__version__) |                               None,__version__) | ||||||
|     if not wfRequest: |     if not wfRequest: | ||||||
|         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/') | ||||||
|  |  | ||||||
							
								
								
									
										85
									
								
								posts.py
								
								
								
								
							
							
						
						
									
										85
									
								
								posts.py
								
								
								
								
							|  | @ -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: [], \ | ||||||
|  | @ -1450,7 +1459,7 @@ def sendToFollowers(session,baseDir: str, \ | ||||||
|             print('Post is not addressed to followers') |             print('Post is not addressed to followers') | ||||||
|         return |         return | ||||||
|     print('Post is addressed to followers') |     print('Post is addressed to followers') | ||||||
| 
 |      | ||||||
|     grouped=groupFollowersByDomain(baseDir,nickname,domain) |     grouped=groupFollowersByDomain(baseDir,nickname,domain) | ||||||
|     if not grouped: |     if not grouped: | ||||||
|         if debug: |         if debug: | ||||||
|  | @ -1467,39 +1476,65 @@ 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 | ||||||
|         if toNickname!='inbox' and postJsonObject.get('type'): |         cc='' | ||||||
|            if postJsonObject['type']=='Update': |         if withSharedInbox: | ||||||
|                if postJsonObject.get('object'): |             toNickname=followerHandles[index].split('@')[0] | ||||||
|                    if isinstance(postJsonObject['object'], dict): |  | ||||||
|                        if postJsonObject['object'].get('type'): |  | ||||||
|                            if postJsonObject['object']['type']=='Person' or \ |  | ||||||
|                               postJsonObject['object']['type']=='Application' or \ |  | ||||||
|                               postJsonObject['object']['type']=='Service': |  | ||||||
|                                print('Sending profile update to shared inbox of '+toDomain) |  | ||||||
|                                toNickname='inbox' |  | ||||||
| 
 | 
 | ||||||
|         if debug: |             # if there are more than one followers on the domain | ||||||
|             print('DEBUG: Sending from '+nickname+'@'+domain+' to '+toNickname+'@'+toDomain) |             # then send the post to the shared inbox | ||||||
|         sendSignedJson(postJsonObject,session,baseDir, \ |             if len(followerHandles)>1: | ||||||
|                        nickname,domain,port, \ |                 toNickname='inbox' | ||||||
|                        toNickname,toDomain,toPort, \ | 
 | ||||||
|                        cc,httpPrefix,True,clientToServer, \ |             if toNickname!='inbox' and postJsonObject.get('type'): | ||||||
|                        federationList, \ |                 if postJsonObject['type']=='Update': | ||||||
|                        sendThreads,postLog,cachedWebfingers, \ |                     if postJsonObject.get('object'): | ||||||
|                        personCache,debug,projectVersion) |                         if isinstance(postJsonObject['object'], dict): | ||||||
|  |                             if postJsonObject['object'].get('type'): | ||||||
|  |                                 if postJsonObject['object']['type']=='Person' or \ | ||||||
|  |                                    postJsonObject['object']['type']=='Application' or \ | ||||||
|  |                                    postJsonObject['object']['type']=='Service': | ||||||
|  |                                     print('Sending profile update to shared inbox of '+toDomain) | ||||||
|  |                                     toNickname='inbox' | ||||||
|  |              | ||||||
|  |             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) | ||||||
|  |         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') | ||||||
|          |          | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue