Skip to content

Commit

Permalink
AP: default actors to type Application, add disclaimer with links to …
Browse files Browse the repository at this point in the history
…profile bio

thanks for the nudge @fromjasonstuff!
  • Loading branch information
snarfed committed Jan 12, 2024
1 parent c8e2faf commit e9194b0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
12 changes: 12 additions & 0 deletions activitypub.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
add,
CACHE_TIME,
CONTENT_TYPE_HTML,
DOMAINS,
DOMAIN_RE,
error,
host_url,
Expand Down Expand Up @@ -752,6 +753,17 @@ def postprocess_as2_actor(actor, user):
['https://w3id.org/security/v1']),
})

if (user.key.id() not in DOMAINS
and (not user.direct
# Web users only
or (getattr(user, 'last_webmention_in', 'unset') is None))):
actor['type'] = 'Application'
disclaimer = f'[<a href="https://{PRIMARY_DOMAIN}{user.user_page_path()}">bridged</a> from <a href="{user.web_url()}">{user.handle_or_id()}</a> by <a href="https://{PRIMARY_DOMAIN}/">Bridgy Fed</a>]'
if not actor['summary'].endswith(disclaimer):
if actor['summary']:
actor['summary'] += '\n\n'
actor['summary'] += disclaimer

return actor

# source protocol in subdomain.
Expand Down
6 changes: 4 additions & 2 deletions tests/test_activitypub.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@
'https://www.w3.org/ns/activitystreams',
'https://w3id.org/security/v1',
],
'type': 'Person',
'type': 'Application',
'id': 'http://localhost/user.com',
'url': 'http://localhost/r/https://user.com/',
'preferredUsername': 'user.com',
'summary': '',
'summary': '[<a href="https://fed.brid.gy/web/user.com">bridged</a> from <a href="https://user.com/">user.com</a> by <a href="https://fed.brid.gy/">Bridgy Fed</a>]',
'inbox': 'http://localhost/user.com/inbox',
'outbox': 'http://localhost/user.com/outbox',
'following': 'http://localhost/user.com/following',
Expand Down Expand Up @@ -437,6 +437,8 @@ def test_actor_handle_new_user(self, _, __, ___):
self.assert_equals({
**ACTOR,
**ACTOR_FAKE,
'summary': '[<a href="https://fed.brid.gy/fa/fake:handle:user">bridged</a> from <a href="fake:user">fake:handle:user</a> by <a href="https://fed.brid.gy/">Bridgy Fed</a>]',
'type': 'Application',
}, got.json, ignore=['publicKeyPem'])

def test_actor_no_handle(self, *_):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@
'urls': [{'value': 'https://user.com/', 'displayName': 'Ms. ☕ Baz'}],
}
ACTOR_AS2 = {
'type': 'Person',
'type': 'Application',
'id': 'http://localhost/user.com',
'url': 'http://localhost/r/https://user.com/',
'name': 'Ms. ☕ Baz',
'summary': '[<a href="https://fed.brid.gy/web/user.com">bridged</a> from <a href="https://user.com/">user.com</a> by <a href="https://fed.brid.gy/">Bridgy Fed</a>]',
'preferredUsername': 'user.com',
'inbox': 'http://localhost/user.com/inbox',
'outbox': 'http://localhost/user.com/outbox',
Expand Down

0 comments on commit e9194b0

Please sign in to comment.