From c391e7bc4151ae148d42acd8bbe303338cdde31c Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Mon, 7 Nov 2022 00:19:00 -0700 Subject: THE FOLLOWS, THEY WORK Well, in one direction anyway --- users/models/identity.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'users/models/identity.py') diff --git a/users/models/identity.py b/users/models/identity.py index 1f44e98..98262bc 100644 --- a/users/models/identity.py +++ b/users/models/identity.py @@ -82,11 +82,7 @@ class Identity(models.Model): view = "/@{self.username}@{self.domain_id}/" view_short = "/@{self.username}/" action = "{view}action/" - actor = "{view}actor/" activate = "{view}activate/" - key = "{actor}#main-key" - inbox = "{actor}inbox/" - outbox = "{actor}outbox/" def get_scheme(self, url): return "https" @@ -102,12 +98,9 @@ class Identity(models.Model): ### Alternate constructors/fetchers ### @classmethod - def by_handle(cls, handle, fetch=False, local=False): - if handle.startswith("@"): - raise ValueError("Handle must not start with @") - if "@" not in handle: - raise ValueError("Handle must contain domain") - username, domain = handle.split("@") + def by_username_and_domain(cls, username, domain, fetch=False, local=False): + if username.startswith("@"): + raise ValueError("Username must not start with @") try: if local: return cls.objects.get(username=username, domain_id=domain, local=True) @@ -115,7 +108,9 @@ class Identity(models.Model): return cls.objects.get(username=username, domain_id=domain) except cls.DoesNotExist: if fetch and not local: - actor_uri, handle = async_to_sync(cls.fetch_webfinger)(handle) + actor_uri, handle = async_to_sync(cls.fetch_webfinger)( + f"{username}@{domain}" + ) username, domain = handle.split("@") domain = Domain.get_remote_domain(domain) return cls.objects.create( @@ -168,6 +163,10 @@ class Identity(models.Model): # TODO: Setting return self.data_age > 60 * 24 * 24 + @property + def key_id(self): + return self.actor_uri + "#main-key" + ### Actor/Webfinger fetching ### @classmethod -- cgit v1.2.3