Filter followers only in place

It's only used in one spot
This commit is contained in:
Mouse Reeve 2021-10-06 11:12:03 -07:00
parent 68b6b1fbae
commit 2307cb2227
2 changed files with 8 additions and 13 deletions

View file

@ -140,7 +140,12 @@ class HomeStream(ActivityStream):
return models.Status.privacy_filter(
user,
privacy_levels=["public", "unlisted", "followers"],
following_only=True,
).exclude(
~Q( # remove everything except
Q(user__followers=user) # user following
| Q(user=user) # is self
| Q(mention_users=user) # mentions user
),
)

View file

@ -107,7 +107,7 @@ class BookWyrmModel(models.Model):
raise PermissionDenied()
@classmethod
def privacy_filter(cls, viewer, privacy_levels=None, following_only=False):
def privacy_filter(cls, viewer, privacy_levels=None):
"""filter objects that have "user" and "privacy" fields"""
queryset = cls.objects
if hasattr(queryset, "select_subclasses"):
@ -135,17 +135,7 @@ class BookWyrmModel(models.Model):
# filter to only privided privacy levels
queryset = queryset.filter(privacy__in=privacy_levels)
# only include statuses the user follows
if following_only:
queryset = queryset.exclude(
~Q( # remove everythign except
Q(user__followers=viewer)
| Q(user=viewer) # user following
| Q(mention_users=viewer) # is self # mentions user
),
)
# exclude followers-only statuses the user doesn't follow
elif "followers" in privacy_levels:
if "followers" in privacy_levels:
queryset = cls.followers_filter(queryset, viewer)
# exclude direct messages not intended for the user