kopia lustrzana https://github.com/snarfed/bridgy-fed
rodzic
ea1f3dce49
commit
5ec2159546
17
atproto.py
17
atproto.py
|
@ -147,6 +147,23 @@ class ATProto(User, Protocol):
|
||||||
def profile_id(self):
|
def profile_id(self):
|
||||||
return self.profile_at_uri(self.key.id())
|
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
|
@classmethod
|
||||||
def target_for(cls, obj, shared=False):
|
def target_for(cls, obj, shared=False):
|
||||||
"""Returns our PDS URL as the target for the given object.
|
"""Returns our PDS URL as the target for the given object.
|
||||||
|
|
|
@ -354,14 +354,14 @@ class Protocol:
|
||||||
return (None, None)
|
return (None, None)
|
||||||
|
|
||||||
@classmethod
|
@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.
|
"""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`
|
For example, for Web user ``alice.com``, :meth:`ATProto.bridged_web_url_for`
|
||||||
returns ``https://bsky.app/profile/alice.com.web.brid.gy``
|
returns ``https://bsky.app/profile/alice.com.web.brid.gy``
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
proto (str or Protocol)
|
user (models.User)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
str, or None if there isn't a canonical URL
|
str, or None if there isn't a canonical URL
|
||||||
|
|
|
@ -62,10 +62,13 @@
|
||||||
{% if proto and not isinstance(user, proto)
|
{% if proto and not isinstance(user, proto)
|
||||||
and proto.LABEL not in ('ui', 'web')
|
and proto.LABEL not in ('ui', 'web')
|
||||||
and (proto.LABEL not in ids.COPIES_PROTOCOLS or proto.LABEL in copies) %}
|
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)">
|
<nobr title="{{ proto.__name__ }} (bridged)">
|
||||||
|
{% if url %} <a href="{{ url }}"> {% endif %}
|
||||||
<span class="logo">{{ proto.LOGO_HTML|safe }}</span>
|
<span class="logo">{{ proto.LOGO_HTML|safe }}</span>
|
||||||
{{ user.handle_as(proto) }}
|
{{ user.handle_as(proto) }}
|
||||||
|
{% if url %} </a> {% endif %}
|
||||||
</nobr>
|
</nobr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -142,6 +142,17 @@ class ATProtoTest(TestCase):
|
||||||
def test_handle_to_id_not_found(self, *_):
|
def test_handle_to_id_not_found(self, *_):
|
||||||
self.assertIsNone(ATProto.handle_to_id('han.dull'))
|
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):
|
def test_pds_for_did_no_doc(self):
|
||||||
self.assertIsNone(ATProto.pds_for(Object(id='did:plc:user')))
|
self.assertIsNone(ATProto.pds_for(Object(id='did:plc:user')))
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue