make ids.translate_handle support protocol bot users

pull/968/head
Ryan Barrett 2024-04-23 15:01:29 -07:00
rodzic 0e8b9ece7e
commit ce23a72549
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 8 dodań i 6 usunięć

5
ids.py
Wyświetl plik

@ -166,8 +166,9 @@ def translate_handle(*, handle, from_, to, enhanced):
case _, 'atproto' | 'nostr':
handle = handle.lstrip('@').replace('@', '.')
return (handle if enhanced
else f'{handle}.{from_.ABBREV}{SUPERDOMAIN}')
if enhanced or handle == PRIMARY_DOMAIN or handle in PROTOCOL_DOMAINS:
return handle
return f'{handle}.{from_.ABBREV}{SUPERDOMAIN}'
case 'activitypub', 'web':
user, instance = handle.lstrip('@').split('@')

Wyświetl plik

@ -109,10 +109,6 @@ class IdsTest(TestCase):
(Web, 'user.com', Fake, 'fake:handle:user.com'),
(Web, 'user.com', Web, 'user.com'),
# instance actor, protocol bot user
(Web, 'fed.brid.gy', ActivityPub, '@fed.brid.gy@fed.brid.gy'),
(Web, 'bsky.brid.gy', ActivityPub, '@bsky.brid.gy@bsky.brid.gy'),
(ActivityPub, '@user@instance', ActivityPub, '@user@instance'),
(ActivityPub, '@user@instance', ATProto, 'user.instance.ap.brid.gy'),
(ActivityPub, '@user@instance', Fake, 'fake:handle:@user@instance'),
@ -127,6 +123,11 @@ class IdsTest(TestCase):
(Fake, 'fake:handle:user', ATProto, 'fake:handle:user.fa.brid.gy'),
(Fake, 'fake:handle:user', Fake, 'fake:handle:user'),
(Fake, 'fake:handle:user', Web, 'fake:handle:user'),
# instance actor, protocol bot users
(Web, 'fed.brid.gy', ActivityPub, '@fed.brid.gy@fed.brid.gy'),
(Web, 'bsky.brid.gy', ActivityPub, '@bsky.brid.gy@bsky.brid.gy'),
(Web, 'ap.brid.gy', ATProto, 'ap.brid.gy'),
]:
with self.subTest(from_=from_.LABEL, to=to.LABEL):
self.assertEqual(expected, translate_handle(