user page: link to bridged Bluesky profile

for #825
pull/962/head
Ryan Barrett 2024-04-12 08:46:59 -07:00
rodzic ea1f3dce49
commit 5ec2159546
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
4 zmienionych plików z 33 dodań i 2 usunięć

Wyświetl plik

@ -147,6 +147,23 @@ class ATProto(User, Protocol):
def profile_id(self):
return self.profile_at_uri(self.key.id())
@classmethod
def bridged_web_url_for(cls, user):
"""Returns a bridged user's profile URL on bsky.app.
For example, returns ``https://bsky.app/profile/alice.com.web.brid.gy``
for Web user ``alice.com``.
Args:
user (models.User)
Returns:
str, or None if there isn't a canonical URL
"""
if not isinstance(user, ATProto):
if did := user.get_copy(ATProto):
return bluesky.Bluesky.user_url(did_to_handle(did) or did)
@classmethod
def target_for(cls, obj, shared=False):
"""Returns our PDS URL as the target for the given object.

Wyświetl plik

@ -354,14 +354,14 @@ class Protocol:
return (None, None)
@classmethod
def bridged_web_url_for(self, user):
def bridged_web_url_for(cls, 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)
user (models.User)
Returns:
str, or None if there isn't a canonical URL

Wyświetl plik

@ -62,10 +62,13 @@
{% if proto and not isinstance(user, proto)
and proto.LABEL not in ('ui', 'web')
and (proto.LABEL not in ids.COPIES_PROTOCOLS or proto.LABEL in copies) %}
{% set url = proto.bridged_web_url_for(user) %}
·
<nobr title="{{ proto.__name__ }} (bridged)">
{% if url %} <a href="{{ url }}"> {% endif %}
<span class="logo">{{ proto.LOGO_HTML|safe }}</span>
{{ user.handle_as(proto) }}
{% if url %} </a> {% endif %}
</nobr>
{% endif %}
{% endfor %}

Wyświetl plik

@ -142,6 +142,17 @@ class ATProtoTest(TestCase):
def test_handle_to_id_not_found(self, *_):
self.assertIsNone(ATProto.handle_to_id('han.dull'))
def test_bridged_web_url_for(self):
self.assertIsNone(ATProto.bridged_web_url_for(ATProto(id='did:plc:foo')))
fake = Fake(id='fake:user')
self.assertIsNone(ATProto.bridged_web_url_for(fake))
fake.copies = [Target(uri='did:plc:user', protocol='atproto')]
self.store_object(id='did:plc:user', raw=DID_DOC)
self.assertEqual('https://bsky.app/profile/han.dull',
ATProto.bridged_web_url_for(fake))
def test_pds_for_did_no_doc(self):
self.assertIsNone(ATProto.pds_for(Object(id='did:plc:user')))