summaryrefslogtreecommitdiffstats
path: root/users/models
diff options
context:
space:
mode:
authorAndrew Godwin2022-11-07 00:19:00 -0700
committerAndrew Godwin2022-11-07 00:19:00 -0700
commitc391e7bc4151ae148d42acd8bbe303338cdde31c (patch)
treed2b79043a63b52ec4692469eab596d831d396b9a /users/models
parentfb6c409a9af5b8a686e977ee2251c359071e0ec3 (diff)
downloadtakahe-c391e7bc4151ae148d42acd8bbe303338cdde31c.tar.gz
takahe-c391e7bc4151ae148d42acd8bbe303338cdde31c.tar.bz2
takahe-c391e7bc4151ae148d42acd8bbe303338cdde31c.zip
THE FOLLOWS, THEY WORK
Well, in one direction anyway
Diffstat (limited to 'users/models')
-rw-r--r--users/models/identity.py21
1 files changed, 10 insertions, 11 deletions
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