Support resolving group handles

merge-requests/30/head
Bob Mottram 2021-07-29 12:25:01 +01:00
parent 9f58bb4b6f
commit 2e4832fc52
1 changed files with 38 additions and 25 deletions

View File

@ -1207,6 +1207,7 @@ def getActorJson(hostDomain: str, handle: str, http: bool, gnunet: bool,
if debug: if debug:
print('getActorJson for ' + handle) print('getActorJson for ' + handle)
originalActor = handle originalActor = handle
requiresWebfinger = True
# try to determine the users path # try to determine the users path
detectedUsersPath = _detectUsersPath(handle) detectedUsersPath = _detectUsersPath(handle)
@ -1214,6 +1215,8 @@ def getActorJson(hostDomain: str, handle: str, http: bool, gnunet: bool,
detectedUsersPath in handle or \ detectedUsersPath in handle or \
handle.startswith('http') or \ handle.startswith('http') or \
handle.startswith('hyper'): handle.startswith('hyper'):
if detectedUsersPath == '/c/':
requiresWebfinger = False
# format: https://domain/@nick # format: https://domain/@nick
originalHandle = handle originalHandle = handle
if not hasUsersPath(originalHandle): if not hasUsersPath(originalHandle):
@ -1252,6 +1255,10 @@ def getActorJson(hostDomain: str, handle: str, http: bool, gnunet: bool,
return None, None return None, None
if handle.startswith('@'): if handle.startswith('@'):
handle = handle[1:] handle = handle[1:]
elif handle.startswith('!'):
# handle for a group
handle = handle[1:]
requiresWebfinger = False
if '@' not in handle: if '@' not in handle:
if not quiet: if not quiet:
print('getActorJsonSyntax: --actor nickname@domain') print('getActorJsonSyntax: --actor nickname@domain')
@ -1281,32 +1288,38 @@ def getActorJson(hostDomain: str, handle: str, http: bool, gnunet: bool,
nickname = domain nickname = domain
handle = nickname + '@' + domain handle = nickname + '@' + domain
wfRequest = webfingerHandle(session, handle, if requiresWebfinger:
httpPrefix, cachedWebfingers, # person actor requires webfinger
None, __version__, debug) wfRequest = webfingerHandle(session, handle,
if not wfRequest: httpPrefix, cachedWebfingers,
if not quiet: None, __version__, debug)
print('getActorJson Unable to webfinger ' + handle) if not wfRequest:
return None, None if not quiet:
if not isinstance(wfRequest, dict): print('getActorJson Unable to webfinger ' + handle)
if not quiet:
print('getActorJson Webfinger for ' + handle +
' did not return a dict. ' + str(wfRequest))
return None, None
if not quiet:
pprint(wfRequest)
personUrl = None
if wfRequest.get('errors'):
if not quiet or debug:
print('getActorJson wfRequest error: ' + str(wfRequest['errors']))
if hasUsersPath(handle):
personUrl = originalActor
else:
if debug:
print('No users path in ' + handle)
return None, None return None, None
if not isinstance(wfRequest, dict):
if not quiet:
print('getActorJson Webfinger for ' + handle +
' did not return a dict. ' + str(wfRequest))
return None, None
if not quiet:
pprint(wfRequest)
personUrl = None
if wfRequest.get('errors'):
if not quiet or debug:
print('getActorJson wfRequest error: ' +
str(wfRequest['errors']))
if hasUsersPath(handle):
personUrl = originalActor
else:
if debug:
print('No users path in ' + handle)
return None, None
else:
# group actor only needs a json http GET
personUrl = originalActor
profileStr = 'https://www.w3.org/ns/activitystreams' profileStr = 'https://www.w3.org/ns/activitystreams'
headersList = ( headersList = (