From 52adfbf5da882461cb84f81bcbb944cf24b2091e Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 14 Jun 2021 14:47:59 -0700 Subject: [PATCH] Don't show duplicated statuses after boosts --- bookwyrm/activitystreams.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/bookwyrm/activitystreams.py b/bookwyrm/activitystreams.py index ff3c55fb..a49a7ce4 100644 --- a/bookwyrm/activitystreams.py +++ b/bookwyrm/activitystreams.py @@ -201,6 +201,19 @@ def add_status_on_create(sender, instance, created, *args, **kwargs): for stream in streams.values(): stream.add_status(instance) + if sender != models.Boost: + return + # remove the original post and other, earlier boosts + boosted = instance.boost.boosted_status + old_versions = models.Boost.objects.filter( + boosted_status__id=boosted.id, + created_date__lt=instance.created_date, + ) + for stream in streams.values(): + stream.remove_object_from_related_stores(boosted) + for status in old_versions: + stream.remove_object_from_related_stores(status) + @receiver(signals.post_delete, sender=models.Boost) # pylint: disable=unused-argument @@ -208,7 +221,10 @@ def remove_boost_on_delete(sender, instance, *args, **kwargs): """boosts are deleted""" # we're only interested in new statuses for stream in streams.values(): + # remove the boost stream.remove_object_from_related_stores(instance) + # re-add the original status + stream.add_status(instance.boosted_status) @receiver(signals.post_save, sender=models.UserFollows)