From ea1f3dce496ce3cabe758bacefdc739468c345f7 Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Fri, 12 Apr 2024 07:15:33 -0700 Subject: [PATCH] user page bug fix for 133d640f1d14856963470542a24d688f8f1c4e10 --- models.py | 45 ++++++++++++++++++++++----------------------- protocol.py | 15 +++++++++++++++ 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/models.py b/models.py index d6163ca..feed650 100644 --- a/models.py +++ b/models.py @@ -1271,33 +1271,32 @@ def fetch_objects(query, by=None, user=None): 'content': 'their profile', 'url': id, }) - elif url: + elif url and not content: # heuristics for sniffing URLs and converting them to more friendly # phrases and user handles. # TODO: standardize this into granary.as2 somewhere? - if not content: - from activitypub import FEDI_URL_RE - from atproto import COLLECTION_TO_TYPE, did_to_handle + from activitypub import FEDI_URL_RE + from atproto import COLLECTION_TO_TYPE, did_to_handle - if match := FEDI_URL_RE.match(url): - content = '@' + match.group(2) - if match.group(4): - content += "'s post" - elif match := BSKY_APP_URL_RE.match(url): - id = match.group('id') - if id.startswith('did:'): - id = ATdid_to_handle(id) or id - content = '@' + id - if match.group('tid'): - content += "'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 - if coll := match.group('collection'): - content += f"'s {COLLECTION_TO_TYPE.get(coll) or 'post'}" - url = bluesky.at_uri_to_web_url(url) + if match := FEDI_URL_RE.match(url): + content = '@' + match.group(2) + if match.group(4): + content += "'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 + if match.group('tid'): + content += "'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 + if coll := match.group('collection'): + content += f"'s {COLLECTION_TO_TYPE.get(coll) or 'post'}" + url = bluesky.at_uri_to_web_url(url) content = common.pretty_link(url, text=content, user=user) diff --git a/protocol.py b/protocol.py index 537c4f5..29b963d 100644 --- a/protocol.py +++ b/protocol.py @@ -353,6 +353,21 @@ class Protocol: return (None, None) + @classmethod + def bridged_web_url_for(self, user): + """Returns the web URL for a user's bridged profile in this protocol. + + For example, for Web user ``alice.com``, :meth:`ATProto.bridged_web_url_for` + returns ``https://bsky.app/profile/alice.com.web.brid.gy`` + + Args: + proto (str or Protocol) + + Returns: + str, or None if there isn't a canonical URL + """ + return None + @classmethod def actor_key(cls, obj): """Returns the :class:`User`: key for a given object's author or actor.