mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 19:41:11 +00:00
Filter followers only in place
It's only used in one spot
This commit is contained in:
parent
68b6b1fbae
commit
2307cb2227
2 changed files with 8 additions and 13 deletions
|
@ -140,7 +140,12 @@ class HomeStream(ActivityStream):
|
||||||
return models.Status.privacy_filter(
|
return models.Status.privacy_filter(
|
||||||
user,
|
user,
|
||||||
privacy_levels=["public", "unlisted", "followers"],
|
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
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,7 @@ class BookWyrmModel(models.Model):
|
||||||
raise PermissionDenied()
|
raise PermissionDenied()
|
||||||
|
|
||||||
@classmethod
|
@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"""
|
"""filter objects that have "user" and "privacy" fields"""
|
||||||
queryset = cls.objects
|
queryset = cls.objects
|
||||||
if hasattr(queryset, "select_subclasses"):
|
if hasattr(queryset, "select_subclasses"):
|
||||||
|
@ -135,17 +135,7 @@ class BookWyrmModel(models.Model):
|
||||||
# filter to only privided privacy levels
|
# filter to only privided privacy levels
|
||||||
queryset = queryset.filter(privacy__in=privacy_levels)
|
queryset = queryset.filter(privacy__in=privacy_levels)
|
||||||
|
|
||||||
# only include statuses the user follows
|
if "followers" in privacy_levels:
|
||||||
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:
|
|
||||||
queryset = cls.followers_filter(queryset, viewer)
|
queryset = cls.followers_filter(queryset, viewer)
|
||||||
|
|
||||||
# exclude direct messages not intended for the user
|
# exclude direct messages not intended for the user
|
||||||
|
|
Loading…
Reference in a new issue