Don't show deleted follows, and sort publicly

pull/226/head
Andrew Godwin 2022-12-21 20:56:52 +00:00
rodzic 23db8f3dd8
commit 13ebe14cf9
3 zmienionych plików z 20 dodań i 10 usunięć

Wyświetl plik

@ -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")
)

Wyświetl plik

@ -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

Wyświetl plik

@ -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:
"""