diff options
author | Andrew Godwin | 2022-11-09 23:48:31 -0700 |
---|---|---|
committer | Andrew Godwin | 2022-11-09 23:48:31 -0700 |
commit | 2c3a1299709f2612e96c37e4e121c83ad4df7a56 (patch) | |
tree | 89c2aed22a7a10730e02c809f83b744a21e295e1 /users/models/follow.py | |
parent | 7746abbbb7700fa918450101bbc6d29ed9b4b608 (diff) | |
download | takahe-2c3a1299709f2612e96c37e4e121c83ad4df7a56.tar.gz takahe-2c3a1299709f2612e96c37e4e121c83ad4df7a56.tar.bz2 takahe-2c3a1299709f2612e96c37e4e121c83ad4df7a56.zip |
Profile fetching now working on state machine
Diffstat (limited to 'users/models/follow.py')
-rw-r--r-- | users/models/follow.py | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/users/models/follow.py b/users/models/follow.py index 3325a0b..6f62481 100644 --- a/users/models/follow.py +++ b/users/models/follow.py @@ -6,16 +6,20 @@ from stator.models import State, StateField, StateGraph, StatorModel class FollowStates(StateGraph): - pending = State(try_interval=30) - requested = State() + unrequested = State(try_interval=30) + requested = State(try_interval=24 * 60 * 60) accepted = State() - @pending.add_transition(requested) - async def try_request(instance: "Follow"): # type:ignore + unrequested.transitions_to(requested) + requested.transitions_to(accepted) + + @classmethod + async def handle_unrequested(cls, instance: "Follow"): print("Would have tried to follow on", instance) - return False - requested.add_manual_transition(accepted) + @classmethod + async def handle_requested(cls, instance: "Follow"): + print("Would have tried to requested on", instance) class Follow(StatorModel): @@ -73,3 +77,17 @@ class Follow(StatorModel): follow.state = FollowStates.accepted follow.save() return follow + + @classmethod + def remote_created(cls, source, target, uri): + follow = cls.maybe_get(source=source, target=target) + if follow is None: + follow = Follow.objects.create(source=source, target=target, uri=uri) + if follow.state == FollowStates.fresh: + follow.transition_perform(FollowStates.requested) + + @classmethod + def remote_accepted(cls, source, target): + follow = cls.maybe_get(source=source, target=target) + if follow and follow.state == FollowStates.requested: + follow.transition_perform(FollowStates.accepted) |