diff --git a/users/models/follow.py b/users/models/follow.py index e96e988..697c464 100644 --- a/users/models/follow.py +++ b/users/models/follow.py @@ -9,15 +9,17 @@ from users.models.identity import Identity class FollowStates(StateGraph): - unrequested = State(try_interval=300) + unrequested = State(try_interval=600) local_requested = State(try_interval=24 * 60 * 60) remote_requested = State(try_interval=24 * 60 * 60) accepted = State(externally_progressed=True) undone = State(try_interval=60 * 60) undone_remotely = State() + failed = State() unrequested.transitions_to(local_requested) unrequested.transitions_to(remote_requested) + unrequested.times_out_to(failed, seconds=86400 * 7) local_requested.transitions_to(accepted) remote_requested.transitions_to(accepted) accepted.transitions_to(undone) @@ -37,6 +39,11 @@ class FollowStates(StateGraph): # Remote follows should not be here if not follow.source.local: return cls.remote_requested + if follow.target.local: + return cls.accepted + # Don't try if the other identity didn't fetch yet + if not follow.target.inbox_uri: + return # Sign it and send it try: await follow.source.signed_request( diff --git a/users/services/identity.py b/users/services/identity.py index 867a2c3..e6b44f4 100644 --- a/users/services/identity.py +++ b/users/services/identity.py @@ -22,6 +22,7 @@ class IdentityService: elif existing_follow.state in [ FollowStates.undone, FollowStates.undone_remotely, + FollowStates.failed, ]: existing_follow.transition_perform(FollowStates.unrequested) return cast(Follow, existing_follow) @@ -41,22 +42,14 @@ class IdentityService: """ return { "id": self.identity.pk, - "following": self.identity.inbound_follows.filter(source=from_identity) - .exclude( - state__in=[ - FollowStates.undone, - FollowStates.undone_remotely, - ] - ) - .exists(), - "followed_by": self.identity.outbound_follows.filter(target=from_identity) - .exclude( - state__in=[ - FollowStates.undone, - FollowStates.undone_remotely, - ] - ) - .exists(), + "following": self.identity.inbound_follows.filter( + source=from_identity, + state__in=FollowStates.group_active(), + ).exists(), + "followed_by": self.identity.outbound_follows.filter( + target=from_identity, + state__in=FollowStates.group_active(), + ).exists(), "showing_reblogs": True, "notifying": False, "blocking": False,