Don't show deleted follows, and sort publicly

This commit is contained in:
Andrew Godwin 2022-12-21 20:56:52 +00:00
parent 23db8f3dd8
commit 13ebe14cf9
3 changed files with 20 additions and 10 deletions

View file

@ -3,7 +3,7 @@ from django.utils.decorators import method_decorator
from django.views.generic import ListView from django.views.generic import ListView
from users.decorators import identity_required 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") @method_decorator(identity_required, name="dispatch")
@ -39,6 +39,8 @@ class Follows(ListView):
"source", "source",
"source__domain", "source__domain",
) )
.exclude(source__state__in=IdentityStates.group_deleted())
.exclude(target__state__in=IdentityStates.group_deleted())
.order_by("-created") .order_by("-created")
) )

View file

@ -53,6 +53,10 @@ class IdentityStates(StateGraph):
outdated.transitions_to(updated) outdated.transitions_to(updated)
updated.transitions_to(outdated) updated.transitions_to(outdated)
@classmethod
def group_deleted(cls):
return [cls.deleted, cls.deleted_fanned_out]
@classmethod @classmethod
async def targets_fan_out(cls, identity: "Identity", type_: str) -> None: async def targets_fan_out(cls, identity: "Identity", type_: str) -> None:
from activities.models import FanOut from activities.models import FanOut
@ -115,9 +119,7 @@ class IdentityStates(StateGraph):
class IdentityQuerySet(models.QuerySet): class IdentityQuerySet(models.QuerySet):
def not_deleted(self): def not_deleted(self):
query = self.exclude( query = self.exclude(state__in=IdentityStates.group_deleted())
state__in=[IdentityStates.deleted, IdentityStates.deleted_fanned_out]
)
return query return query

View file

@ -16,14 +16,20 @@ class IdentityService:
self.identity = identity self.identity = identity
def following(self) -> models.QuerySet[Identity]: def following(self) -> models.QuerySet[Identity]:
return Identity.objects.filter( return (
inbound_follows__source=self.identity Identity.objects.filter(inbound_follows__source=self.identity)
).not_deleted() .not_deleted()
.order_by("username")
.select_related("domain")
)
def followers(self) -> models.QuerySet[Identity]: def followers(self) -> models.QuerySet[Identity]:
return Identity.objects.filter( return (
outbound_follows__target=self.identity Identity.objects.filter(outbound_follows__target=self.identity)
).not_deleted() .not_deleted()
.order_by("username")
.select_related("domain")
)
def follow_from(self, from_identity: Identity) -> Follow: def follow_from(self, from_identity: Identity) -> Follow:
""" """