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

', + 'attributedTo': 'did:alice', + '_misskey_quote': 'https://bsky.brid.gy/convert/ap/at://did:bob/app.bsky.feed.post/456', + 'quoteUrl': 'https://bsky.brid.gy/convert/ap/at://did:bob/app.bsky.feed.post/456', + 'tag': [{ + 'type': 'Link', + 'mediaType': as2.CONTENT_TYPE_LD_PROFILE, + 'href': 'https://bsky.brid.gy/convert/ap/at://did:bob/app.bsky.feed.post/456', + 'name': 'RE: https://bsky.app/profile/did:bob/post/456', + }], + }, ActivityPub.convert(obj), ignore=['contentMap', 'content_is_html', 'to']) + def test_postprocess_as2_idempotent(self): for obj in (ACTOR, REPLY_OBJECT, REPLY_OBJECT_WRAPPED, REPLY, NOTE_OBJECT, NOTE, MENTION_OBJECT, MENTION, LIKE, diff --git a/tests/test_protocol.py b/tests/test_protocol.py index 319c4ecb..ab4fca7b 100644 --- a/tests/test_protocol.py +++ b/tests/test_protocol.py @@ -536,7 +536,8 @@ def test_translate_ids_attachments_mention_tags(self): 'objectType': 'note', 'attachments': [ {'id': 'other:o:fa:fake:123'}, - {'url': 'other:o:fa:fake:456'}, + {'id': 'other:o:fa:fake:456', + 'url': 'fake:456'}, ], 'tags': [ {'objectType': 'mention', 'url': 'other:u:fake:alice'}, @@ -570,7 +571,8 @@ def test_translate_ids_copies(self): }, 'attachments': [{ 'objectType': 'note', - 'url': 'other:post', + 'id': 'other:post', + 'url': 'fake:post', }], }, OtherFake.translate_ids({ 'objectType': 'activity',