From b5a0386cd007e37b59e9fa2dad131cbbea46dd1f Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Tue, 7 Feb 2023 12:43:36 -0800 Subject: [PATCH] store home page URL in update profile Objects, render better in activities UI fixes #407 --- pages.py | 13 ++++++++----- tests/test_webmention.py | 5 ++++- webmention.py | 4 +++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/pages.py b/pages.py index bd4b448..0159c22 100644 --- a/pages.py +++ b/pages.py @@ -207,12 +207,15 @@ def fetch_objects(query, user): or inner_obj.get('displayName') or inner_obj.get('summary')) url = util.get_first(inner_obj, 'url') or inner_obj.get('id') - if url: - content = common.pretty_link(url, text=content, user=user) - elif (obj.domains and - obj_as1.get('id', '').strip('/') == f'https://{obj.domains[0]}'): + if (obj.domains and + inner_obj.get('id', '').strip('/') == f'https://{obj.domains[0]}'): obj.phrase = 'updated' - obj_as1['content'] = 'their profile' + obj_as1.update({ + 'content': 'their profile', + 'url': f'https://{obj.domains[0]}', + }) + elif url: + content = common.pretty_link(url, text=content, user=user) obj.content = (obj_as1.get('content') or obj_as1.get('displayName') diff --git a/tests/test_webmention.py b/tests/test_webmention.py index 3e91507..d741d0e 100644 --- a/tests/test_webmention.py +++ b/tests/test_webmention.py @@ -1102,10 +1102,12 @@ class WebmentionTest(testutil.TestCase): )) id = 'https://orig/#update-2022-01-02T03:04:05+00:00' + wrapped_id = f'http://localhost/r/{id}' self.assert_deliveries(mock_post, ('https://shared/inbox', 'https://inbox'), { '@context': 'https://www.w3.org/ns/activitystreams', 'type': 'Update', - 'id': f'http://localhost/r/{id}', + 'id': wrapped_id, + 'url': wrapped_id, 'actor': 'http://localhost/orig', 'object': { **ACTOR_AS2_FULL, @@ -1116,6 +1118,7 @@ class WebmentionTest(testutil.TestCase): expected_as1 = { 'id': id, + 'url': id, 'objectType': 'activity', 'verb': 'update', 'object': ACTOR_AS1_UNWRAPPED, diff --git a/webmention.py b/webmention.py index 4558080..94d4ee3 100644 --- a/webmention.py +++ b/webmention.py @@ -63,12 +63,14 @@ class Webmention(View): 'objectType': 'activity', 'verb': 'update', 'id': id, + 'url': id, 'object': actor_as1, } self.source_as2 = common.postprocess_as2({ '@context': 'https://www.w3.org/ns/activitystreams', 'type': 'Update', - 'id': common.host_url(f'{source}#update-{util.now().isoformat()}'), + 'id': id, + 'url': id, 'object': actor_as2, }, user=self.user) return self.try_activitypub() or 'No ActivityPub targets'