From 272685f27d6cb37c1d5109f7b28c666bc2ccbe4a Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 6 Feb 2021 21:26:39 -0800 Subject: [PATCH] sketchy fix for boost broadcasting --- bookwyrm/models/activitypub_mixin.py | 7 ++++++- bookwyrm/models/status.py | 13 +++---------- bookwyrm/tests/models/test_status_model.py | 7 +++++++ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/bookwyrm/models/activitypub_mixin.py b/bookwyrm/models/activitypub_mixin.py index 0168dec8..51cce4e6 100644 --- a/bookwyrm/models/activitypub_mixin.py +++ b/bookwyrm/models/activitypub_mixin.py @@ -183,7 +183,12 @@ class ObjectMixin(ActivitypubMixin): # broadcast Create activities for objects owned by a local user if not user or not user.local: return - activity = self.to_create_activity(user) + try: + activity = self.to_create_activity(user) + except KeyError: + # janky as heck, this catches the mutliple inheritence chain + # for boosts and ignores this auxilliary broadcast + return self.broadcast(activity, user) return diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index d15afbfc..ec105a10 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -15,6 +15,7 @@ from .base_model import BookWyrmModel from .fields import image_serializer from . import fields + class Status(OrderedCollectionPageMixin, BookWyrmModel): ''' any post, like a reply to a review, etc ''' user = fields.ForeignKey( @@ -127,14 +128,6 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel): return activity - def save(self, *args, **kwargs): - ''' update user active time ''' - if self.user.local: - self.user.last_active_date = timezone.now() - self.user.save(broadcast=False) - return super().save(*args, **kwargs) - - class GeneratedNote(Status): ''' these are app-generated messages about user activity ''' @property @@ -232,6 +225,8 @@ class Boost(ActivityMixin, Status): related_name='boosters', activitypub_field='object', ) + activity_serializer = activitypub.Boost + def __init__(self, *args, **kwargs): ''' the user field is "actor" here instead of "attributedTo" ''' @@ -245,8 +240,6 @@ class Boost(ActivityMixin, Status): self.image_fields = [] self.deserialize_reverse_fields = [] - activity_serializer = activitypub.Boost - # This constraint can't work as it would cross tables. # class Meta: # unique_together = ('user', 'boosted_status') diff --git a/bookwyrm/tests/models/test_status_model.py b/bookwyrm/tests/models/test_status_model.py index a479a88b..7462c07d 100644 --- a/bookwyrm/tests/models/test_status_model.py +++ b/bookwyrm/tests/models/test_status_model.py @@ -29,6 +29,7 @@ class Status(TestCase): 'test.jpg', ContentFile(output.getvalue()) ) + models.Status.broadcast = lambda x, y, z: None def test_status_generated_fields(self): ''' setting remote id ''' @@ -239,6 +240,12 @@ class Status(TestCase): def test_favorite(self): ''' fav a status ''' + def fav_broadcast_mock(_, activity, user): + ''' ok ''' + self.assertEqual(user.remote_id, self.user.remote_id) + self.assertEqual(activity['type'], 'Like') + models.Favorite.broadcast = fav_broadcast_mock + status = models.Status.objects.create( content='test content', user=self.user) fav = models.Favorite.objects.create(status=status, user=self.user)