activitypub.postprocess_as2: fix de-duping image attachments

for https://github.com/snarfed/bridgy-fed/issues/1000#issuecomment-2119106644
pull/1067/head
Ryan Barrett 2024-05-19 15:38:13 -07:00
rodzic 7cf8a77a73
commit ec350e7fa6
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 25 dodań i 5 usunięć

Wyświetl plik

@ -685,8 +685,10 @@ def postprocess_as2(activity, orig_obj=None, wrap=True):
imgs = util.get_list(obj_or_activity, 'image')
if imgs:
atts = obj_or_activity['attachment']
atts.extend((img if isinstance(img, dict) else {'url': img})
for img in imgs if img not in atts)
for img in imgs:
if isinstance(img, str):
img = {'url': img}
add(atts, img)
# cc target's author(s), recipients, mentions
# https://www.w3.org/TR/activitystreams-vocabulary/#audienceTargeting

Wyświetl plik

@ -1950,15 +1950,33 @@ class ActivityPubUtilsTest(TestCase):
'image': [{'url': 'http://r/foo'}, {'url': 'http://r/bar'}],
}))
def test_postprocess_as2_image_bare_string_url(self):
def test_postprocess_as2_object_image_bare_string_url(self):
self.assert_equals({
'id': 'http://localhost/r/xyz',
'attachment': [{'url': 'http://r/foo'}],
'image': ['http://r/foo'],
'image': 'http://r/foo',
'to': [as2.PUBLIC_AUDIENCE],
}, postprocess_as2({
'id': 'xyz',
'image': ['http://r/foo'],
'image': 'http://r/foo',
}))
def test_postprocess_as2_create_activity_image_bare_string_url(self):
self.assert_equals({
'type': 'Create',
'object': {
'id': 'http://localhost/r/xyz',
'attachment': [{'url': 'http://r/foo'}],
'image': ['http://r/foo'],
'to': [as2.PUBLIC_AUDIENCE],
},
'to': [as2.PUBLIC_AUDIENCE],
}, postprocess_as2({
'type': 'Create',
'object': {
'id': 'xyz',
'image': ['http://r/foo'],
},
}))
def test_postprocess_as2_note(self):