diff --git a/models.py b/models.py index feed650..52fbdb3 100644 --- a/models.py +++ b/models.py @@ -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) diff --git a/pages.py b/pages.py index fc797a8..bac5d18 100644 --- a/pages.py +++ b/pages.py @@ -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'