kopia lustrzana https://github.com/snarfed/bridgy-fed
add User.profile_id, implement in ATProto
rodzic
e257d43f21
commit
452e49134d
|
@ -109,6 +109,9 @@ class ATProto(User, Protocol):
|
|||
|
||||
return did.resolve_handle(handle, get_fn=util.requests_get)
|
||||
|
||||
def profile_id(self):
|
||||
return f'at://{self.key.id()}/app.bsky.actor.profile/self'
|
||||
|
||||
@classmethod
|
||||
def target_for(cls, obj, shared=False):
|
||||
"""Returns the PDS URL for the given object, or None.
|
||||
|
|
16
models.py
16
models.py
|
@ -398,6 +398,22 @@ class User(StringIdModel, metaclass=ProtocolUserMeta):
|
|||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def profile_id(self):
|
||||
"""Returns the id of this user's profile object in its native protocol.
|
||||
|
||||
Examples:
|
||||
|
||||
* Web: home page URL, eg ``https://me.com/``
|
||||
* ActivityPub: actor URL, eg ``https://instance.com/users/me``
|
||||
* ATProto: profile AT URI, eg ``at://did:plc:123/app.bsky.actor.profile/self``
|
||||
|
||||
Defaults to this user's key id.
|
||||
|
||||
Returns:
|
||||
str
|
||||
"""
|
||||
return self.key.id()
|
||||
|
||||
def user_page_path(self, rest=None):
|
||||
"""Returns the user's Bridgy Fed user page path."""
|
||||
path = f'/{self.ABBREV}/{self.readable_or_key_id()}'
|
||||
|
|
|
@ -238,6 +238,10 @@ class ATProtoTest(TestCase):
|
|||
self.store_object(id='did:plc:foo', raw=DID_DOC)
|
||||
self.assertEqual('@han.dull@atproto.brid.gy', user.ap_address())
|
||||
|
||||
def test_profile_id(self):
|
||||
self.assertEqual('at://did:plc:foo/app.bsky.actor.profile/self',
|
||||
self.make_user('did:plc:foo', cls=ATProto).profile_id())
|
||||
|
||||
@patch.object(tasks_client, 'create_task', return_value=Task(name='my task'))
|
||||
@patch('requests.post',
|
||||
return_value=requests_response('OK')) # create DID on PLC
|
||||
|
|
Ładowanie…
Reference in New Issue