mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-27 20:11:14 +00:00
sketchy fix for boost broadcasting
This commit is contained in:
parent
63fe9777e2
commit
272685f27d
3 changed files with 16 additions and 11 deletions
|
@ -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
|
||||
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
|
||||
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue