From 08dc5b4d8617c1dde4e18e35948a0eb52b3b86d3 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 17 Feb 2021 11:45:21 -0800 Subject: [PATCH] Fixes unfollow --- bookwyrm/models/relationship.py | 14 ++++++++++++-- bookwyrm/tests/views/test_follow.py | 1 - 2 files changed, 12 insertions(+), 3 deletions(-) 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)