Skip to content

Commit caced3d

Browse files
committed
Protocol.check_supported: allow empty content if there's a link attachment
for #2658 [deploy]
1 parent 362a60c commit caced3d

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

protocol.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,15 +2467,21 @@ def check_supported(cls, obj, direction):
24672467
and inner_type not in cls.SUPPORTED_AS1_TYPES)):
24682468
error(f"Bridgy Fed for {cls.LABEL} doesn't support {obj.type} {inner_type} yet", status=204)
24692469

2470-
# don't allow posts with blank content and no image/video/audio
2470+
# don't allow posts with blank content and no image/video/audio/link
24712471
crud_obj = (as1.get_object(obj.as1) if obj.type in ('post', 'update')
24722472
else obj.as1)
2473+
links = [att for att in as1.get_objects(crud_obj, 'attachments')
2474+
if att.get('objectType') == 'link']
24732475
if (crud_obj.get('objectType') in as1.POST_TYPES
24742476
and not util.get_url(crud_obj, key='image')
2475-
and not any(util.get_urls(crud_obj, 'attachments', inner_key='stream'))
2477+
and not util.get_urls(crud_obj, 'attachments', inner_key='stream')
2478+
# link attachments get moved into content, eg in
2479+
# activitypub.postprocess_as2
2480+
# https://github.com/snarfed/bridgy-fed/issues/2658
2481+
and not any(util.get_url(l) for l in links)
24762482
# TODO: handle articles with displayName but not content
24772483
and not source.html_to_text(crud_obj.get('content')).strip()):
2478-
error('Blank content and no image or video or audio', status=204)
2484+
error('Blank content and no image or video or audio or link', status=204)
24792485

24802486
# receiving DMs is only allowed to protocol bot accounts
24812487
if direction == 'receive':

tests/test_protocol.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,10 +1515,31 @@ def test_check_supported(self):
15151515
'object': {'objectType': 'note'}},
15161516
{'objectType': 'activity', 'verb': 'update',
15171517
'object': {'objectType': 'note'}},
1518+
# link attachment with no url
1519+
{'objectType': 'note',
1520+
'attachments': [{'objectType': 'link', 'displayName': 'foo'}]},
15181521
):
15191522
with self.subTest(obj=obj), self.assertRaises(NoContent):
15201523
Fake.check_supported(Object(our_as1=obj), 'receive')
15211524

1525+
# blank content but link attachment
1526+
# https://github.com/snarfed/bridgy-fed/issues/2658
1527+
for obj in ({
1528+
'objectType': 'note',
1529+
'attachments': [{'objectType': 'link', 'url': 'http://a/link'}],
1530+
}, {
1531+
'objectType': 'activity', 'verb': 'post',
1532+
'object': {
1533+
'objectType': 'note',
1534+
'attachments': [{
1535+
'objectType': 'link',
1536+
'url': 'http://a/link',
1537+
}],
1538+
},
1539+
}):
1540+
with self.subTest(obj=obj):
1541+
Fake.check_supported(Object(our_as1=obj), 'receive')
1542+
15221543
# from and to a copy id of a protocol bot user
15231544
self.make_user(cls=Web, id='ap.brid.gy',
15241545
copies=[Target(protocol='fake', uri='fake:ap-bot')])

0 commit comments

Comments
 (0)