diff --git a/activities/views/follows.py b/activities/views/follows.py index d315b34..9713296 100644 --- a/activities/views/follows.py +++ b/activities/views/follows.py @@ -3,7 +3,7 @@ from django.utils.decorators import method_decorator from django.views.generic import ListView from users.decorators import identity_required -from users.models import Follow, FollowStates +from users.models import Follow, FollowStates, IdentityStates @method_decorator(identity_required, name="dispatch") @@ -39,6 +39,8 @@ class Follows(ListView): "source", "source__domain", ) + .exclude(source__state__in=IdentityStates.group_deleted()) + .exclude(target__state__in=IdentityStates.group_deleted()) .order_by("-created") ) diff --git a/users/models/identity.py b/users/models/identity.py index 589018b..f4f635f 100644 --- a/users/models/identity.py +++ b/users/models/identity.py @@ -53,6 +53,10 @@ class IdentityStates(StateGraph): outdated.transitions_to(updated) updated.transitions_to(outdated) + @classmethod + def group_deleted(cls): + return [cls.deleted, cls.deleted_fanned_out] + @classmethod async def targets_fan_out(cls, identity: "Identity", type_: str) -> None: from activities.models import FanOut @@ -115,9 +119,7 @@ class IdentityStates(StateGraph): class IdentityQuerySet(models.QuerySet): def not_deleted(self): - query = self.exclude( - state__in=[IdentityStates.deleted, IdentityStates.deleted_fanned_out] - ) + query = self.exclude(state__in=IdentityStates.group_deleted()) return query diff --git a/users/services/identity.py b/users/services/identity.py index 6558275..4f06aa8 100644 --- a/users/services/identity.py +++ b/users/services/identity.py @@ -16,14 +16,20 @@ class IdentityService: self.identity = identity def following(self) -> models.QuerySet[Identity]: - return Identity.objects.filter( - inbound_follows__source=self.identity - ).not_deleted() + return ( + Identity.objects.filter(inbound_follows__source=self.identity) + .not_deleted() + .order_by("username") + .select_related("domain") + ) def followers(self) -> models.QuerySet[Identity]: - return Identity.objects.filter( - outbound_follows__target=self.identity - ).not_deleted() + return ( + Identity.objects.filter(outbound_follows__target=self.identity) + .not_deleted() + .order_by("username") + .select_related("domain") + ) def follow_from(self, from_identity: Identity) -> Follow: """