diff --git a/protocol.py b/protocol.py index eec10ecf..0c18a819 100644 --- a/protocol.py +++ b/protocol.py @@ -723,7 +723,10 @@ def translate(elem, field, fn): translate(tag, 'url', translate_user_id) for att in as1.get_objects(o, 'attachments'): translate(att, 'id', translate_object_id) - translate(att, 'url', translate_object_id) + url = att.get('url') + if url and not att.get('id'): + from_cls = Protocol.for_id(url) + att['id'] = translate_object_id(from_=from_cls, to=to_cls, id=url) outer_obj = util.trim_nulls(outer_obj) if outer_obj.get('object', {}).keys() == {'id'}: diff --git a/tests/test_activitypub.py b/tests/test_activitypub.py index bfcd9bde..f433fdac 100644 --- a/tests/test_activitypub.py +++ b/tests/test_activitypub.py @@ -2557,6 +2557,35 @@ def test_convert_adds_context_to_as2(self): 'object': ACTOR, }, ActivityPub.convert(obj)) + def test_convert_quote_post(self): + obj = Object(id='at://did:alice/app.bsky.feed.post/123', bsky={ + '$type': 'app.bsky.feed.post', + 'text': 'foo bar', + 'embed': { + '$type': 'app.bsky.embed.record', + 'record': { + 'cid': 'bafyreih...', + 'uri': 'at://did:bob/app.bsky.feed.post/456' + } + }, + }) + + self.assert_equals({ + 'type': 'Note', + 'id': 'https://bsky.brid.gy/convert/ap/at://did:alice/app.bsky.feed.post/123', + 'url': 'http://localhost/r/https://bsky.app/profile/did:alice/post/123', + 'content': '
foo bar
RE: https://bsky.app/profile/did:bob/post/456