diff --git a/README.md b/README.md index b34629e0..6e22ddf9 100644 --- a/README.md +++ b/README.md @@ -328,6 +328,7 @@ Changelog * Strip trailing slash from home page URLs in order to remove visible `/` from rel-me verified links on Mastodon etc. * Convert `attributedTo` to singular if it has only one element. * If `name` isn't set, fall back to `preferredUsername` or infer Webfinger handle from `id` or `url`. + * Prioritize bsky.app profile URL before handle URL in `url` field ([bridgy#1640](https://github.com/snarfed/bridgy/issues/1640)). * `facebook`: * Remove `Facebook.fql_stream_to_post`. [Facebook turned down FQL in 2016.](https://en.wikipedia.org/wiki/Facebook_Query_Language#History) * `github`: diff --git a/granary/bluesky.py b/granary/bluesky.py index 5d9d2525..dd107042 100644 --- a/granary/bluesky.py +++ b/granary/bluesky.py @@ -645,9 +645,9 @@ def to_as1(obj, type=None, uri=None, repo_did=None, repo_handle=None, urls = [] if handle: + urls.append(Bluesky.user_url(handle)) if not util.domain_or_parent_in(handle, [DEFAULT_PDS_DOMAIN]): urls.append(f'https://{handle}/') - urls.append(Bluesky.user_url(handle)) elif did and did.startswith('did:web:'): urls.extend([did_web_to_url(did), Bluesky.user_url(did)]) diff --git a/granary/tests/test_bluesky.py b/granary/tests/test_bluesky.py index 905b73a0..75c7d1b9 100644 --- a/granary/tests/test_bluesky.py +++ b/granary/tests/test_bluesky.py @@ -105,11 +105,11 @@ POST_AUTHOR_PROFILE_AS = copy.deepcopy(POST_AUTHOR_AS) POST_AUTHOR_PROFILE_AS['object']['author'].update({ 'username': 'alice.com', - 'url': ['https://alice.com/', 'https://bsky.app/profile/alice.com'], + 'url': ['https://bsky.app/profile/alice.com', 'https://alice.com/'], }) POST_AUTHOR_PROFILE_AS['actor'].update({ 'username': 'alice.com', - 'url': ['https://alice.com/', 'https://bsky.app/profile/alice.com'], + 'url': ['https://bsky.app/profile/alice.com', 'https://alice.com/'], }) POST_AUTHOR_BSKY = copy.deepcopy(POST_VIEW_BSKY) POST_AUTHOR_BSKY['author'] = { @@ -246,14 +246,14 @@ 'objectType': 'person', 'id': 'did:web:bob.com', 'displayName': 'Bob', - 'url': ['https://bob.com/', 'https://bsky.app/profile/bob.com'], + 'url': ['https://bsky.app/profile/bob.com', 'https://bob.com/'], }, 'object': POST_AUTHOR_PROFILE_AS['object'], } REPOST_PROFILE_AS = copy.deepcopy(REPOST_AS) REPOST_PROFILE_AS['actor'].update({ 'username': 'bob.com', - 'url': ['https://bob.com/', 'https://bsky.app/profile/bob.com'], + 'url': ['https://bsky.app/profile/bob.com', 'https://bob.com/'], }) REPOST_BSKY = { @@ -294,12 +294,12 @@ THREAD_AS['object']['author'] = ACTOR_AS THREAD_AS['object']['author'].update({ 'username': 'alice.com', - 'url': ['https://alice.com/', 'https://bsky.app/profile/alice.com'], + 'url': ['https://bsky.app/profile/alice.com', 'https://alice.com/'], }) THREAD_AS['object']['url'] = 'https://bsky.app/profile/alice.com/post/tid' THREAD_AS['actor'].update({ 'username': 'alice.com', - 'url': ['https://alice.com/', 'https://bsky.app/profile/alice.com'], + 'url': ['https://bsky.app/profile/alice.com', 'https://alice.com/'], }) THREAD_BSKY = { @@ -368,7 +368,7 @@ POST_AUTHOR_PROFILE_WITH_LIKES_AS['object']['tags'][0]['author'].update({ 'id': 'tag:bsky.app:did:web:alice.com', 'username': 'alice.com', - 'url': ['https://alice.com/', 'https://bsky.app/profile/alice.com'], + 'url': ['https://bsky.app/profile/alice.com', 'https://alice.com/'], }) POST_AUTHOR_PROFILE_WITH_REPOSTS_AS = copy.deepcopy(POST_AUTHOR_PROFILE_AS) @@ -383,7 +383,7 @@ POST_AUTHOR_PROFILE_WITH_REPOSTS_AS['object']['tags'][0]['author'].update({ 'id': 'tag:bsky.app:did:web:alice.com', 'username': 'alice.com', - 'url': ['https://alice.com/', 'https://bsky.app/profile/alice.com'], + 'url': ['https://bsky.app/profile/alice.com', 'https://alice.com/'], }) class BlueskyTest(testutil.TestCase): @@ -394,7 +394,8 @@ def setUp(self): def assert_equals(self, expected, actual, ignore=(), **kwargs): ignore = list(ignore) + ['uri'] - return super().assert_equals(expected, actual, ignore=ignore, **kwargs) + return super().assert_equals(expected, actual, ignore=ignore, in_order=True, + **kwargs) def assert_call(self, mock, url, json=None): mock.assert_any_call(url, data=None, json=json, headers={ @@ -783,7 +784,7 @@ def test_to_as1_profile(self): 'objectType': 'featured', 'url': OLD_BLOB_URL, }], - 'url': ['https://han.dull/', 'https://bsky.app/profile/han.dull'], + 'url': ['https://bsky.app/profile/han.dull', 'https://han.dull/'], }, to_as1(ACTOR_PROFILE_BSKY, repo_did='did:plc:foo', repo_handle='han.dull')) def test_to_as1_profile_bsky_social_handle_is_not_url(self): @@ -797,7 +798,7 @@ def test_to_as1_profile_view(self): self.assert_equals({ **ACTOR_AS, 'username': 'alice.com', - 'url': ['https://alice.com/', 'https://bsky.app/profile/alice.com'], + 'url': ['https://bsky.app/profile/alice.com', 'https://alice.com/'], }, to_as1(ACTOR_PROFILE_VIEW_BSKY)) def test_to_as1_profile_no_repo_did_handle_or_pds(self): @@ -911,7 +912,7 @@ def test_to_as1_listView(self): 'author': { 'objectType': 'person', 'id': 'did:alice', - 'url': ['https://alice.com/', 'https://bsky.app/profile/alice.com'], + 'url': ['https://bsky.app/profile/alice.com', 'https://alice.com/'], 'username': 'alice.com', 'image': [{'url': 'https://cdn.bsky.app/alice@jpeg'}] } diff --git a/granary/tests/testdata/actor.as-from-bsky.json b/granary/tests/testdata/actor.as-from-bsky.json index 9b0d00f1..4826c5ed 100644 --- a/granary/tests/testdata/actor.as-from-bsky.json +++ b/granary/tests/testdata/actor.as-from-bsky.json @@ -10,5 +10,5 @@ "displayName": "Martin Smith", "username": "example.com", "summary": "this is my bio", - "url": ["https://example.com/", "https://bsky.app/profile/example.com"] + "url": ["https://bsky.app/profile/example.com", "https://example.com/"] } diff --git a/granary/tests/testdata/actor_with_featured.as-from-bsky.json b/granary/tests/testdata/actor_with_featured.as-from-bsky.json index 7ac15e4f..256bc098 100644 --- a/granary/tests/testdata/actor_with_featured.as-from-bsky.json +++ b/granary/tests/testdata/actor_with_featured.as-from-bsky.json @@ -3,5 +3,5 @@ "id": "did:plc:foo", "displayName": "Martin Smith", "username": "example.com", - "url": ["https://example.com/", "https://bsky.app/profile/example.com"] + "url": ["https://bsky.app/profile/example.com", "https://example.com/"] } diff --git a/granary/tests/testdata/note.as-from-bsky.json b/granary/tests/testdata/note.as-from-bsky.json index 2dac832b..17401cec 100644 --- a/granary/tests/testdata/note.as-from-bsky.json +++ b/granary/tests/testdata/note.as-from-bsky.json @@ -8,7 +8,7 @@ "author": { "objectType": "person", "id": "did:plc:asdf", - "url": ["https://example.com/", "https://bsky.app/profile/example.com"], + "url": ["https://bsky.app/profile/example.com", "https://example.com/"], "displayName": "Ryan Barrett", "username": "example.com" }, diff --git a/granary/tests/testdata/quote.as-from-bsky.json b/granary/tests/testdata/quote.as-from-bsky.json index 146baf8c..9371693d 100644 --- a/granary/tests/testdata/quote.as-from-bsky.json +++ b/granary/tests/testdata/quote.as-from-bsky.json @@ -21,7 +21,7 @@ "author": { "objectType": "person", "id": "did:plc:pv7fudn", - "url": ["https://alice.example.com/", "https://bsky.app/profile/alice.example.com"], + "url": ["https://bsky.app/profile/alice.example.com", "https://alice.example.com/"], "displayName": "Alice", "username": "alice.example.com", "image": [{"url": "https://cdn.bsky.social/imgproxy/alice/pv7fudn@jpeg"}] diff --git a/granary/tests/testdata/repost.as-from-bsky.json b/granary/tests/testdata/repost.as-from-bsky.json index 6ac3ec5f..20385e98 100644 --- a/granary/tests/testdata/repost.as-from-bsky.json +++ b/granary/tests/testdata/repost.as-from-bsky.json @@ -7,7 +7,7 @@ "author": { "objectType": "person", "id": "did:web:example.com", - "url": ["https://example.com/", "https://bsky.app/profile/example.com"], + "url": ["https://bsky.app/profile/example.com", "https://example.com/"], "displayName": "Bob", "username": "example.com" }, @@ -17,7 +17,7 @@ "actor": { "objectType": "person", "id": "did:web:alice.example.com", - "url": ["https://alice.example.com/", "https://bsky.app/profile/alice.example.com"], + "url": ["https://bsky.app/profile/alice.example.com", "https://alice.example.com/"], "displayName": "Alice", "username": "alice.example.com" }