sketchy fix for boost broadcasting
This commit is contained in:
parent
63fe9777e2
commit
272685f27d
@ -183,7 +183,12 @@ class ObjectMixin(ActivitypubMixin):
|
|||||||
# broadcast Create activities for objects owned by a local user
|
# broadcast Create activities for objects owned by a local user
|
||||||
if not user or not user.local:
|
if not user or not user.local:
|
||||||
return
|
return
|
||||||
|
try:
|
||||||
activity = self.to_create_activity(user)
|
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)
|
self.broadcast(activity, user)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ from .base_model import BookWyrmModel
|
|||||||
from .fields import image_serializer
|
from .fields import image_serializer
|
||||||
from . import fields
|
from . import fields
|
||||||
|
|
||||||
|
|
||||||
class Status(OrderedCollectionPageMixin, BookWyrmModel):
|
class Status(OrderedCollectionPageMixin, BookWyrmModel):
|
||||||
''' any post, like a reply to a review, etc '''
|
''' any post, like a reply to a review, etc '''
|
||||||
user = fields.ForeignKey(
|
user = fields.ForeignKey(
|
||||||
@ -127,14 +128,6 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
|
|||||||
return activity
|
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):
|
class GeneratedNote(Status):
|
||||||
''' these are app-generated messages about user activity '''
|
''' these are app-generated messages about user activity '''
|
||||||
@property
|
@property
|
||||||
@ -232,6 +225,8 @@ class Boost(ActivityMixin, Status):
|
|||||||
related_name='boosters',
|
related_name='boosters',
|
||||||
activitypub_field='object',
|
activitypub_field='object',
|
||||||
)
|
)
|
||||||
|
activity_serializer = activitypub.Boost
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
''' the user field is "actor" here instead of "attributedTo" '''
|
''' the user field is "actor" here instead of "attributedTo" '''
|
||||||
@ -245,8 +240,6 @@ class Boost(ActivityMixin, Status):
|
|||||||
self.image_fields = []
|
self.image_fields = []
|
||||||
self.deserialize_reverse_fields = []
|
self.deserialize_reverse_fields = []
|
||||||
|
|
||||||
activity_serializer = activitypub.Boost
|
|
||||||
|
|
||||||
# This constraint can't work as it would cross tables.
|
# This constraint can't work as it would cross tables.
|
||||||
# class Meta:
|
# class Meta:
|
||||||
# unique_together = ('user', 'boosted_status')
|
# unique_together = ('user', 'boosted_status')
|
||||||
|
@ -29,6 +29,7 @@ class Status(TestCase):
|
|||||||
'test.jpg',
|
'test.jpg',
|
||||||
ContentFile(output.getvalue())
|
ContentFile(output.getvalue())
|
||||||
)
|
)
|
||||||
|
models.Status.broadcast = lambda x, y, z: None
|
||||||
|
|
||||||
def test_status_generated_fields(self):
|
def test_status_generated_fields(self):
|
||||||
''' setting remote id '''
|
''' setting remote id '''
|
||||||
@ -239,6 +240,12 @@ class Status(TestCase):
|
|||||||
|
|
||||||
def test_favorite(self):
|
def test_favorite(self):
|
||||||
''' fav a status '''
|
''' 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(
|
status = models.Status.objects.create(
|
||||||
content='test content', user=self.user)
|
content='test content', user=self.user)
|
||||||
fav = models.Favorite.objects.create(status=status, user=self.user)
|
fav = models.Favorite.objects.create(status=status, user=self.user)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user