atproto user pages: render DIDs as handles with profile links

for #825
pull/962/head
Ryan Barrett 2024-04-12 12:34:49 -07:00
rodzic 117e121cd2
commit 2085b131a1
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 17 dodań i 12 usunięć

Wyświetl plik

@ -1278,25 +1278,28 @@ def fetch_objects(query, by=None, user=None):
from activitypub import FEDI_URL_RE
from atproto import COLLECTION_TO_TYPE, did_to_handle
handle = suffix = ''
if match := FEDI_URL_RE.match(url):
content = '@' + match.group(2)
handle = match.group(2)
if match.group(4):
content += "'s post"
suffix = "'s post"
elif match := BSKY_APP_URL_RE.match(url):
id = match.group('id')
if id.startswith('did:'):
id = did_to_handle(id) or id
content = '@' + id
handle = match.group('id')
if match.group('tid'):
content += "'s post"
suffix = "'s post"
elif match := AT_URI_PATTERN.match(url):
id = match.group('repo')
if id.startswith('did:'):
id = did_to_handle(id) or id
content = '@' + id
handle = match.group('repo')
if coll := match.group('collection'):
content += f"'s {COLLECTION_TO_TYPE.get(coll) or 'post'}"
suffix = f"'s {COLLECTION_TO_TYPE.get(coll) or 'post'}"
url = bluesky.at_uri_to_web_url(url)
elif url.startswith('did:'):
handle = url
url = bluesky.Bluesky.user_url(handle)
if handle:
if handle.startswith('did:'):
handle = did_to_handle(handle) or handle
content = f'@{handle}{suffix}'
content = common.pretty_link(url, text=content, user=user)

Wyświetl plik

@ -237,6 +237,8 @@ def serve_feed(*, objects, format, user, title, as_snippets=False, quiet=False):
# TODO: extract a Protocol class method out of User.profile_id,
# then use that here instead. the catch is that we'd need to
# determine Protocol for every id, which is expensive.
#
# same TODO is in models.fetch_objects
id = val['id']
if id.startswith('did:'):
id = f'at://{id}/app.bsky.actor.profile/self'