Skip to content

Commit 21c79a3

Browse files
committed
when converting h-card to actor, use link text or title for profile links
for #331
1 parent a2b9096 commit 21c79a3

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

common.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -566,9 +566,9 @@ def actor(domain, user=None):
566566
if not user:
567567
user = User.get_or_create(domain)
568568

569-
actor = postprocess_as2(
570-
as2.from_as1(microformats2.json_to_object(hcard)), user=user)
571-
actor.update({
569+
actor_as1 = microformats2.json_to_object(hcard, rel_urls=mf2.get('rel-urls'))
570+
actor_as2 = postprocess_as2(as2.from_as1(actor_as1), user=user)
571+
actor_as2.update({
572572
'id': host_url(domain),
573573
# This has to be the domain for Mastodon etc interop! It seems like it
574574
# should be the custom username from the acct: u-url in their h-card,
@@ -585,8 +585,8 @@ def actor(domain, user=None):
585585
},
586586
})
587587

588-
logger.info(f'Generated AS2 actor: {json_dumps(actor, indent=2)}')
589-
return actor
588+
logger.info(f'Generated AS2 actor: {json_dumps(actor_as2, indent=2)}')
589+
return actor_as2
590590

591591

592592
def fetch_followers(domain, collection):

tests/test_activitypub.py

+30-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def test_actor(self, _, mock_get, __):
179179
'url': 'http://localhost/r/https://foo.com/about-me',
180180
'attachment': [{
181181
'type': 'PropertyValue',
182-
'name': 'Link',
182+
'name': 'Mrs. ☕ Foo',
183183
'value': '<a rel=\"me\" href="https://foo.com/about-me">foo.com/about-me</a>',
184184
}],
185185
'inbox': 'http://localhost/foo.com/inbox',
@@ -196,6 +196,35 @@ def test_actor(self, _, mock_get, __):
196196
},
197197
}, got.json)
198198

199+
def test_actor_rel_me_links(self, _, mock_get, __):
200+
mock_get.return_value = requests_response("""
201+
<body>
202+
<div class="h-card">
203+
<a class="u-url" rel="me" href="/about-me">Mrs. ☕ Foo</a>
204+
<a class="u-url" rel="me" href="http://one" title="one title">
205+
one text
206+
</a>
207+
<a class="u-url" rel="me" href="https://two" title=" two title "> </a>
208+
</div>
209+
</body>
210+
""", url='https://foo.com/', content_type=common.CONTENT_TYPE_HTML)
211+
212+
got = self.client.get('/foo.com')
213+
self.assertEqual(200, got.status_code)
214+
self.assertEqual([{
215+
'type': 'PropertyValue',
216+
'name': 'Mrs. ☕ Foo',
217+
'value': '<a rel="me" href="https://foo.com/about-me">foo.com/about-me</a>',
218+
}, {
219+
'type': 'PropertyValue',
220+
'name': 'one text',
221+
'value': '<a rel="me" href="http://one">one</a>',
222+
}, {
223+
'type': 'PropertyValue',
224+
'name': 'two title',
225+
'value': '<a rel="me" href="https://two">two</a>',
226+
}], got.json['attachment'])
227+
199228
def test_actor_no_hcard(self, _, mock_get, __):
200229
mock_get.return_value = requests_response("""
201230
<body>

0 commit comments

Comments
 (0)