postprocess_as2: duplicate content into contentMap.en

for #681. this suppresses Mastodon's Translate link. longer term "right" fix is to actually detect the source's language, if available, and use it instead.
pull/691/head
Ryan Barrett 2023-10-20 13:37:38 -07:00
rodzic 1fa205af30
commit b32045d494
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
4 zmienionych plików z 26 dodań i 13 usunięć

Wyświetl plik

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

Wyświetl plik

@ -1666,10 +1666,13 @@ class ActivityPubUtilsTest(TestCase):
self.assert_equals({
'id': 'http://localhost/r/xyz',
'type': 'Note',
'content': 'foo',
'contentMap': {'en': 'foo'},
'to': [as2.PUBLIC_AUDIENCE],
}, postprocess_as2({
'id': 'xyz',
'type': 'Note',
'content': 'foo',
}))
def test_postprocess_as2_hashtag(self):

Wyświetl plik

@ -15,17 +15,13 @@ from . import testutil
from common import CONTENT_TYPE_HTML
COMMENT_AS2 = {
**as2.to_as1(COMMENT),
**as2.from_as1(COMMENT),
'type': 'Note',
'id': 'https://fed.brid.gy/r/tag:fake.com:123456',
'url': 'https://fed.brid.gy/r/https://fake.com/123456',
'name': 'A ☕ reply',
'inReplyTo': 'https://fake.com/123',
}
COMMENT_AS2_WEB = {
**COMMENT_AS2,
'id': 'https://web.brid.gy/r/tag:fake.com:123456',
'url': 'https://web.brid.gy/r/https://fake.com/123456',
'name': 'A ☕ reply',
'contentMap': {'en': COMMENT['content']},
'inReplyTo': 'https://fake.com/123',
}
HTML = """\
<!DOCTYPE html>
@ -254,7 +250,7 @@ A ☕ reply
resp = self.client.get(f'/convert/ap/{url}',
base_url='https://web.brid.gy/')
self.assertEqual(200, resp.status_code)
self.assert_equals(COMMENT_AS2_WEB, resp.json, ignore=['to'])
self.assert_equals(COMMENT_AS2, resp.json, ignore=['to'])
@patch('requests.get')
def test_web_to_activitypub_fetch(self, mock_get):
@ -267,7 +263,7 @@ A ☕ reply
resp = self.client.get(f'/convert/ap/{url}',
base_url='https://web.brid.gy/')
self.assertEqual(200, resp.status_code)
self.assert_equals(COMMENT_AS2_WEB, resp.json, ignore=['to'])
self.assert_equals(COMMENT_AS2, resp.json, ignore=['to'])
def test_web_to_activitypub_no_user(self):
resp = self.client.get(f'/convert/ap/http://nope.com/post',
@ -282,7 +278,7 @@ A ☕ reply
resp = self.client.get(f'/convert/ap/http://user.com/a%23b',
base_url='https://web.brid.gy/')
self.assertEqual(200, resp.status_code)
self.assert_equals(COMMENT_AS2_WEB, resp.json, ignore=['to'])
self.assert_equals(COMMENT_AS2, resp.json, ignore=['to'])
def test_fed_subdomain(self):
url = 'https://user.com/post'

Wyświetl plik

@ -243,6 +243,12 @@ AS2_CREATE = {
<a class="u-in-reply-to" href="http://not/fediverse"></a>
<a class="u-in-reply-to" href="https://mas.to/toot">foo bar</a>
<a href="http://localhost/"></a>""",
'contentMap': {
'en': """\
<a class="u-in-reply-to" href="http://not/fediverse"></a>
<a class="u-in-reply-to" href="https://mas.to/toot">foo bar</a>
<a href="http://localhost/"></a>""",
},
'inReplyTo': 'https://mas.to/toot/id',
'to': [as2.PUBLIC_AUDIENCE],
'cc': [
@ -347,6 +353,7 @@ NOTE_AS2 = {
'attributedTo': 'http://localhost/user.com',
'name': 'hello i am a post',
'content': 'hello i am a post',
'contentMap': {'en': 'hello i am a post'},
'to': [as2.PUBLIC_AUDIENCE],
}
CREATE_AS1 = {
@ -968,7 +975,7 @@ class WebTest(TestCase):
self.assertEqual(200, got.status_code)
inboxes = ['https://inbox/', 'https://public/inbox', 'https://shared/inbox']
self.assert_deliveries(mock_post, inboxes, {
expected = {
**NOTE_AS2,
'attributedTo': None,
'type': 'Create',
@ -979,7 +986,9 @@ class WebTest(TestCase):
'targetUrl': 'http://bob.com/post',
'to': ['https://www.w3.org/ns/activitystreams#Public'],
},
})
}
del expected['contentMap']
self.assert_deliveries(mock_post, inboxes, expected)
def test_create_default_url_to_wm_source(self, mock_get, mock_post):
"""Source post has no u-url. AS2 id should default to webmention source."""