activitypub.postprocess_as2: linkify indexed tags in content

makes Mastodon etc link them correctly to the local instance's UI in its rendering
pull/1067/head
Ryan Barrett 2024-05-19 20:38:34 -07:00
rodzic 9243e18a4f
commit edf3b5894e
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 32 dodań i 0 usunięć

Wyświetl plik

@ -736,6 +736,8 @@ def postprocess_as2(activity, orig_obj=None, wrap=True):
if not name.startswith('#'):
tag['name'] = f'#{name}'
as2.link_tags(obj_or_activity)
# language, in contentMap
# https://github.com/snarfed/bridgy-fed/issues/681
if content := obj_or_activity.get('content'):

Wyświetl plik

@ -2011,6 +2011,36 @@ class ActivityPubUtilsTest(TestCase):
],
}))
def test_postprocess_as2_plain_text_content_links_hashtags_mentions(self):
expected = 'foo <a href="http://inst/bar">@bar</a> <a href="http://inst/baz">#baz</a>'
self.assert_equals({
'content': expected,
'contentMap': {'en': expected},
'content_is_html': True,
'tag': [{
'type': 'Tag',
'href': 'http://inst/bar',
}, {
'type': 'Mention',
'href': 'http://inst/baz',
}],
'to': [as2.PUBLIC_AUDIENCE],
'cc': ['http://inst/baz'],
}, postprocess_as2({
'content': 'foo @bar #baz',
'tag': [{
'type': 'Tag',
'href': 'http://inst/bar',
'startIndex': 4,
'length': 4,
}, {
'type': 'Mention',
'href': 'http://inst/baz',
'startIndex': 9,
'length': 4,
}],
}))
def test_postprocess_as2_strips_link_attachment(self):
self.assertNotIn('attachment', postprocess_as2({
'type': 'Note',