diff --git a/bookwyrm/models/relationship.py b/bookwyrm/models/relationship.py index 76852988..3e6ac0fb 100644 --- a/bookwyrm/models/relationship.py +++ b/bookwyrm/models/relationship.py @@ -5,7 +5,7 @@ from django.db.models import Q from django.dispatch import receiver from bookwyrm import activitypub -from .activitypub_mixin import ActivitypubMixin, ActivityMixin +from .activitypub_mixin import ActivitypubMixin, ActivityMixin, generate_activity from .base_model import BookWyrmModel from . import fields @@ -56,10 +56,20 @@ class UserRelationship(BookWyrmModel): return '%s#%s/%d' % (base_path, status, self.id) -class UserFollows(ActivitypubMixin, UserRelationship): +class UserFollows(ActivityMixin, UserRelationship): ''' Following a user ''' status = 'follows' + def save(self, *args, **kwargs): + ''' never broadcast a creation (that's handled by "accept"), only a + deletion (an unfollow, as opposed to "reject" and undo pending) ''' + super().save(*args, broadcast=False, **kwargs) + + def to_activity(self): + ''' overrides default to manually set serializer ''' + return activitypub.Follow(**generate_activity(self)) + + @classmethod def from_request(cls, follow_request): ''' converts a follow request into a follow relationship ''' diff --git a/bookwyrm/tests/views/test_follow.py b/bookwyrm/tests/views/test_follow.py index b913c17d..5f61ab03 100644 --- a/bookwyrm/tests/views/test_follow.py +++ b/bookwyrm/tests/views/test_follow.py @@ -104,7 +104,6 @@ class BookViews(TestCase): request.user = self.local_user self.remote_user.followers.add(self.local_user) self.assertEqual(self.remote_user.followers.count(), 1) - # need to see if this ACTUALLY broadcasts with patch('bookwyrm.models.activitypub_mixin.broadcast_task.delay') \ as mock: views.unfollow(request)