user page bug fix for 133d640f1d

pull/962/head
Ryan Barrett 2024-04-12 07:15:33 -07:00
rodzic f67cecd8f9
commit ea1f3dce49
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 37 dodań i 23 usunięć

Wyświetl plik

@ -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)

Wyświetl plik

@ -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.