Skip to content

Commit

Permalink
Protocol.translate_ids: fix user-visible quote post URL
Browse files Browse the repository at this point in the history
broken by a735396, for #1154 and #461
  • Loading branch information
snarfed committed Jun 26, 2024
1 parent 3085012 commit ac2df74
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
5 changes: 4 additions & 1 deletion protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}:
Expand Down
29 changes: 29 additions & 0 deletions tests/test_activitypub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': '<p>foo bar<br><br>RE: <a href="https://bsky.app/profile/did:bob/post/456">https://bsky.app/profile/did:bob/post/456</a></p>',
'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,
Expand Down
6 changes: 4 additions & 2 deletions tests/test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'},
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit ac2df74

Please sign in to comment.