Skip to content

Commit

Permalink
activitypub.postprocess_as2: handle Link objects using href field ins…
Browse files Browse the repository at this point in the history
…tead of url

for #1637, bug fix to match snarfed/granary@14c9653
  • Loading branch information
snarfed committed Dec 19, 2024
1 parent 214f0c3 commit cf6446e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion activitypub.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ def postprocess_as2(activity, orig_obj=None, wrap=True):
link_atts = [a for a in atts if a.get('type') == 'Link']

for link in link_atts:
for url in util.get_list(link, 'url'):
for url in util.get_list(link, 'href'):
if obj_or_activity.setdefault('content', ''):
obj_or_activity['content'] += '<br><br>'
obj_or_activity['content'] += util.pretty_link(url, text=link.get('name'))
Expand Down
28 changes: 25 additions & 3 deletions tests/test_activitypub.py
Original file line number Diff line number Diff line change
Expand Up @@ -2470,11 +2470,11 @@ def test_postprocess_as2_moves_link_attachments_to_content(self):
'type': 'Note',
'attachment': [{
'type': 'Link',
'url': 'http://a/link',
'href': 'http://a/link',
'name': 'check it out',
}, {
'type': 'Link',
'url': 'http://another/link',
'href': 'http://another/link',
}],
}), ignore=['to'])

Expand All @@ -2491,7 +2491,7 @@ def test_postprocess_as2_appends_link_attachments_to_content(self):
'content': 'original',
'attachment': [{
'type': 'Link',
'url': 'http://a/link',
'href': 'http://a/link',
}],
}), ignore=['to'])

Expand Down Expand Up @@ -2933,6 +2933,28 @@ def test_convert_quote_post(self):
}],
}, ActivityPub.convert(obj), ignore=['contentMap', 'to'])

@patch('requests.get', return_value=requests_response())
def test_convert_bluesky_external_embed_to_link_in_content(self, _):
# https://github.com/snarfed/bridgy-fed/issues/1637
self.assert_equals({
'type': 'Note',
'id': 'https://bsky.brid.gy/convert/ap/at://did:bob/app.bsky.feed.post/456',
'url': 'http://localhost/r/https://bsky.app/profile/did:bob/post/456',
'attributedTo': 'did:bob',
'content': '<p>foo bar<br><br><a href="http://a.li/nc">a linc</a></p>',
}, ActivityPub.convert(Object(id='at://did:bob/app.bsky.feed.post/456', bsky={
"$type": "app.bsky.feed.post",
"text": "foo bar",
"embed": {
"$type": "app.bsky.embed.external",
"external": {
"description": "baz biff",
"title": "a linc",
"uri": "http://a.li/nc",
},
},
})), ignore=['@context', 'contentMap', 'to'])

def test_send_convert_mention_non_bridged_id_uses_profile_url(self):
self.store_object(id='did:plc:5zspv27pk4iqtrl2ql2nykjh', raw={'foo': 'bar'})
self.make_user(id='did:plc:5zspv27pk4iqtrl2ql2nykjh', cls=ATProto)
Expand Down

0 comments on commit cf6446e

Please sign in to comment.