Merge pull request #987 from bookwyrm-social/duplicate-boosts

Don't broadcast boosts twice
This commit is contained in:
Mouse Reeve
2021-04-23 11:58:01 -07:00
committed by GitHub
4 changed files with 44 additions and 16 deletions

View File

@ -204,7 +204,9 @@ class ObjectMixin(ActivitypubMixin):
created = created or not bool(self.id)
# first off, we want to save normally no matter what
super().save(*args, **kwargs)
if not broadcast:
if not broadcast or (
hasattr(self, "status_type") and self.status_type == "Announce"
):
return
# this will work for objects owned by a user (lists, shelves)

View File

@ -351,6 +351,16 @@ class Boost(ActivityMixin, Status):
def save(self, *args, **kwargs):
""" save and notify """
# This constraint can't work as it would cross tables.
# class Meta:
# unique_together = ('user', 'boosted_status')
if (
Boost.objects.filter(boosted_status=self.boosted_status, user=self.user)
.exclude(id=self.id)
.exists()
):
return
super().save(*args, **kwargs)
if not self.boosted_status.user.local or self.boosted_status.user == self.user:
return