summaryrefslogtreecommitdiffstats
path: root/users/models
diff options
context:
space:
mode:
authorAndrew Godwin2022-11-09 22:29:33 -0700
committerAndrew Godwin2022-11-09 22:29:49 -0700
commit7746abbbb7700fa918450101bbc6d29ed9b4b608 (patch)
tree8768efd8201faa2fee18e5d3b46f33785002f5d6 /users/models
parent61c324508e62bb640b4526183d0837fc57d742c2 (diff)
downloadtakahe-7746abbbb7700fa918450101bbc6d29ed9b4b608.tar.gz
takahe-7746abbbb7700fa918450101bbc6d29ed9b4b608.tar.bz2
takahe-7746abbbb7700fa918450101bbc6d29ed9b4b608.zip
Most of the way through the stator refactor
Diffstat (limited to 'users/models')
-rw-r--r--users/models/__init__.py4
-rw-r--r--users/models/domain.py2
-rw-r--r--users/models/follow.py14
-rw-r--r--users/models/identity.py16
4 files changed, 21 insertions, 15 deletions
diff --git a/users/models/__init__.py b/users/models/__init__.py
index e1877bc..d46003f 100644
--- a/users/models/__init__.py
+++ b/users/models/__init__.py
@@ -1,6 +1,6 @@
from .block import Block # noqa
from .domain import Domain # noqa
-from .follow import Follow # noqa
-from .identity import Identity # noqa
+from .follow import Follow, FollowStates # noqa
+from .identity import Identity, IdentityStates # noqa
from .user import User # noqa
from .user_event import UserEvent # noqa
diff --git a/users/models/domain.py b/users/models/domain.py
index 8467ac3..4ac6ee9 100644
--- a/users/models/domain.py
+++ b/users/models/domain.py
@@ -55,7 +55,7 @@ class Domain(models.Model):
return cls.objects.create(domain=domain, local=False)
@classmethod
- def get_local_domain(cls, domain: str) -> Optional["Domain"]:
+ def get_domain(cls, domain: str) -> Optional["Domain"]:
try:
return cls.objects.get(
models.Q(domain=domain) | models.Q(service_domain=domain)
diff --git a/users/models/follow.py b/users/models/follow.py
index 04f90ee..3325a0b 100644
--- a/users/models/follow.py
+++ b/users/models/follow.py
@@ -6,13 +6,13 @@ from stator.models import State, StateField, StateGraph, StatorModel
class FollowStates(StateGraph):
- pending = State(try_interval=3600)
+ pending = State(try_interval=30)
requested = State()
accepted = State()
@pending.add_transition(requested)
- async def try_request(cls, instance):
- print("Would have tried to follow")
+ async def try_request(instance: "Follow"): # type:ignore
+ print("Would have tried to follow on", instance)
return False
requested.add_manual_transition(accepted)
@@ -73,11 +73,3 @@ class Follow(StatorModel):
follow.state = FollowStates.accepted
follow.save()
return follow
-
- def undo(self):
- """
- Undoes this follow
- """
- if not self.target.local:
- Task.submit("follow_undo", str(self.pk))
- self.delete()
diff --git a/users/models/identity.py b/users/models/identity.py
index 98262bc..5e2cd06 100644
--- a/users/models/identity.py
+++ b/users/models/identity.py
@@ -14,9 +14,21 @@ from django.utils import timezone
from OpenSSL import crypto
from core.ld import canonicalise
+from stator.models import State, StateField, StateGraph, StatorModel
from users.models.domain import Domain
+class IdentityStates(StateGraph):
+ outdated = State(try_interval=3600)
+ updated = State()
+
+ @outdated.add_transition(updated)
+ async def fetch_identity(identity: "Identity"): # type:ignore
+ if identity.local:
+ return True
+ return await identity.fetch_actor()
+
+
def upload_namer(prefix, instance, filename):
"""
Names uploaded images etc.
@@ -26,7 +38,7 @@ def upload_namer(prefix, instance, filename):
return f"{prefix}/{now.year}/{now.month}/{now.day}/{filename}"
-class Identity(models.Model):
+class Identity(StatorModel):
"""
Represents both local and remote Fediverse identities (actors)
"""
@@ -35,6 +47,8 @@ class Identity(models.Model):
# one around as well for making nice URLs etc.
actor_uri = models.CharField(max_length=500, unique=True)
+ state = StateField(IdentityStates)
+
local = models.BooleanField()
users = models.ManyToManyField("users.User", related_name="identities")