From cc97c52d12bb2f4ce451290aab2d17c5b109bb86 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sun, 21 Aug 2022 09:33:43 +1000 Subject: [PATCH] make get_audience logic clearer Retains 'direct' messages at the top of the logic tree to make it easier to understand. In practice because direct messages are excluded from feeds anyway, this doesn't seem to make much difference, but it's easier to read. --- bookwyrm/activitystreams.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/bookwyrm/activitystreams.py b/bookwyrm/activitystreams.py index 90404f1c3..f8312f063 100644 --- a/bookwyrm/activitystreams.py +++ b/bookwyrm/activitystreams.py @@ -111,8 +111,15 @@ class ActivityStream(RedisStore): Q(id__in=status.user.blocks.all()) | Q(blocks=status.user) # not blocked ) + # only visible to the poster and mentioned users + if status.privacy == "direct": + audience = audience.filter( + Q(id=status.user.id) # if the user is the post's author + | Q(id__in=status.mention_users.all()) # if the user is mentioned + ) + # don't show replies to statuses the user can't see - if status.reply_parent and status.reply_parent.privacy == "followers": + elif status.reply_parent and status.reply_parent.privacy == "followers": audience = audience.filter( Q(id=status.user.id) # if the user is the post's author | Q(id=status.reply_parent.user.id) # if the user is the OG author @@ -121,12 +128,6 @@ class ActivityStream(RedisStore): ) # if the user is following both authors ).distinct() - # only visible to the poster and mentioned users - elif status.privacy == "direct": - audience = audience.filter( - Q(id=status.user.id) # if the user is the post's author - | Q(id__in=status.mention_users.all()) # if the user is mentioned - ) # only visible to the poster's followers and tagged users elif status.privacy == "followers": audience = audience.filter(