From 5fe5f0495518e43aa4ab9f6831c4bc27a0be9458 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Fri, 25 Nov 2022 18:20:59 -0700 Subject: Exclude replies in most situations from timelines --- activities/models/fan_out.py | 22 ++++++++++++++++------ activities/views/timelines.py | 10 ++++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/activities/models/fan_out.py b/activities/models/fan_out.py index 5eb20f3..3e5c4da 100644 --- a/activities/models/fan_out.py +++ b/activities/models/fan_out.py @@ -23,13 +23,23 @@ class FanOutStates(StateGraph): post = await fan_out.subject_post.afetch_full() if fan_out.identity.local: # Make a timeline event directly - # TODO: Exclude replies to people we don't follow - await sync_to_async(TimelineEvent.add_post)( - identity=fan_out.identity, - post=post, - ) + # If it's a reply, we only add it if we follow at least one + # of the people mentioned. + add = True + mentioned = {identity.id for identity in post.mentions.all()} + if post.in_reply_to: + add = False + async for follow in fan_out.identity.outbound_follows.all(): + if follow.target_id in mentioned: + add = True + break + if add: + await sync_to_async(TimelineEvent.add_post)( + identity=fan_out.identity, + post=post, + ) # We might have been mentioned - if fan_out.identity in list(post.mentions.all()): + if fan_out.identity.id in mentioned: TimelineEvent.add_mentioned( identity=fan_out.identity, post=post, diff --git a/activities/views/timelines.py b/activities/views/timelines.py index 0c5de0e..b680c8a 100644 --- a/activities/views/timelines.py +++ b/activities/views/timelines.py @@ -71,7 +71,11 @@ class Local(ListView): def get_queryset(self): return ( - Post.objects.filter(visibility=Post.Visibilities.public, author__local=True) + Post.objects.filter( + visibility=Post.Visibilities.public, + author__local=True, + in_reply_to__isnull=True, + ) .select_related("author") .prefetch_related("attachments") .order_by("-created")[:50] @@ -97,7 +101,9 @@ class Federated(ListView): def get_queryset(self): return ( - Post.objects.filter(visibility=Post.Visibilities.public) + Post.objects.filter( + visibility=Post.Visibilities.public, in_reply_to__isnull=True + ) .select_related("author") .prefetch_related("attachments") .order_by("-created")[:50] -- cgit v1.2.3