diff --git a/activitypub.py b/activitypub.py index 380259c..b814610 100644 --- a/activitypub.py +++ b/activitypub.py @@ -744,7 +744,7 @@ def postprocess_as2_actor(actor, user=None): # required by pixelfed. https://github.com/snarfed/bridgy-fed/issues/39 actor.setdefault('summary', '') - if not actor.get('publicKey'): + if not actor.get('publicKey') and not isinstance(user, ActivityPub): # underspecified, inferred from this issue and Mastodon's implementation: # https://github.com/w3c/activitypub/issues/203#issuecomment-297553229 # https://github.com/tootsuite/mastodon/blob/bc2c263504e584e154384ecc2d804aeb1afb1ba3/app/services/activitypub/process_account_service.rb#L77 @@ -897,6 +897,12 @@ def follower_collection(id, collection): TODO: unify page generation with outbox() """ + if (request.path.startswith('/ap/') + and request.host in (PRIMARY_DOMAIN,) + LOCAL_DOMAINS): + # UI request. unfortunate that the URL paths overlap like this! + import pages + return pages.followers_or_following('ap', id, collection) + protocol = Protocol.for_request(fed='web') assert protocol user = protocol.get_by_id(id) diff --git a/pages.py b/pages.py index b68bddd..cb3dc1f 100644 --- a/pages.py +++ b/pages.py @@ -20,7 +20,6 @@ from oauth_dropins.webutil.flask_util import ( redirect, ) -from activitypub import ActivityPub import common from common import DOMAIN_RE from flask_app import app, cache @@ -169,7 +168,8 @@ def followers_or_following(protocol, id, collection): f'{collection}.html', address=request.args.get('address'), follow_url=request.values.get('url'), - ActivityPub=ActivityPub, + # TODO: remove + ActivityPub=PROTOCOLS['activitypub'], **TEMPLATE_VARS, **locals(), ) diff --git a/templates/_followers.html b/templates/_followers.html index 38edc6f..b07af52 100644 --- a/templates/_followers.html +++ b/templates/_followers.html @@ -11,7 +11,8 @@ {% endif %} {% endwith %} {{ user_as1.get('displayName') or '' }} - {{ as2.address(ActivityPub.convert(f.user.obj) or url) or url }} + + {{ as2.address(ActivityPub.convert(f.user.obj, from_user=user) or url) or url }} {% endwith %} diff --git a/tests/test_pages.py b/tests/test_pages.py index 2016cbe..277c279 100644 --- a/tests/test_pages.py +++ b/tests/test_pages.py @@ -232,6 +232,18 @@ class PagesTest(TestCase): got = self.client.get('/fake/fake:foo/followers') self.assert_equals(200, got.status_code) + def test_followers_activitypub(self): + obj = Object(id='https://inst/user', as2={ + 'id': 'https://inst/user', + 'preferredUsername': 'user', + }) + obj.put() + self.make_user('https://inst/user', cls=ActivityPub, obj=obj) + + got = self.client.get('/ap/@user@inst/followers') + self.assert_equals(200, got.status_code) + self.assert_equals('text/html', got.headers['Content-Type'].split(';')[0]) + def test_followers_empty(self): got = self.client.get('/web/user.com/followers') self.assert_equals(200, got.status_code)