Skip to content

Commit

Permalink
ActivityPub.postprocess_as2: always populate images into attachments …
Browse files Browse the repository at this point in the history
…as objects

hopefully for #1000 (comment), ATProto images without alt text not showing up in AP
  • Loading branch information
snarfed committed May 19, 2024
1 parent 976653d commit 7cf8a77
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion activitypub.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,8 @@ 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 for img in imgs if img not in atts)
atts.extend((img if isinstance(img, dict) else {'url': img})
for img in imgs if img not in atts)

# cc target's author(s), recipients, mentions
# https://www.w3.org/TR/activitystreams-vocabulary/#audienceTargeting
Expand Down
11 changes: 11 additions & 0 deletions tests/test_activitypub.py
Original file line number Diff line number Diff line change
Expand Up @@ -1950,6 +1950,17 @@ def test_postprocess_as2_multiple_image(self):
'image': [{'url': 'http://r/foo'}, {'url': 'http://r/bar'}],
}))

def test_postprocess_as2_image_bare_string_url(self):
self.assert_equals({
'id': 'http://localhost/r/xyz',
'attachment': [{'url': 'http://r/foo'}],
'image': ['http://r/foo'],
'to': [as2.PUBLIC_AUDIENCE],
}, postprocess_as2({
'id': 'xyz',
'image': ['http://r/foo'],
}))

def test_postprocess_as2_note(self):
self.assert_equals({
'id': 'http://localhost/r/xyz',
Expand Down

0 comments on commit 7cf8a77

Please sign in to comment.