Fixes unfollow
This commit is contained in:
		| @@ -5,7 +5,7 @@ from django.db.models import Q | |||||||
| from django.dispatch import receiver | from django.dispatch import receiver | ||||||
|  |  | ||||||
| from bookwyrm import activitypub | from bookwyrm import activitypub | ||||||
| from .activitypub_mixin import ActivitypubMixin, ActivityMixin | from .activitypub_mixin import ActivitypubMixin, ActivityMixin, generate_activity | ||||||
| from .base_model import BookWyrmModel | from .base_model import BookWyrmModel | ||||||
| from . import fields | from . import fields | ||||||
|  |  | ||||||
| @@ -56,10 +56,20 @@ class UserRelationship(BookWyrmModel): | |||||||
|         return '%s#%s/%d' % (base_path, status, self.id) |         return '%s#%s/%d' % (base_path, status, self.id) | ||||||
|  |  | ||||||
|  |  | ||||||
| class UserFollows(ActivitypubMixin, UserRelationship): | class UserFollows(ActivityMixin, UserRelationship): | ||||||
|     ''' Following a user ''' |     ''' Following a user ''' | ||||||
|     status = 'follows' |     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 |     @classmethod | ||||||
|     def from_request(cls, follow_request): |     def from_request(cls, follow_request): | ||||||
|         ''' converts a follow request into a follow relationship ''' |         ''' converts a follow request into a follow relationship ''' | ||||||
|   | |||||||
| @@ -104,7 +104,6 @@ class BookViews(TestCase): | |||||||
|         request.user = self.local_user |         request.user = self.local_user | ||||||
|         self.remote_user.followers.add(self.local_user) |         self.remote_user.followers.add(self.local_user) | ||||||
|         self.assertEqual(self.remote_user.followers.count(), 1) |         self.assertEqual(self.remote_user.followers.count(), 1) | ||||||
|         # need to see if this ACTUALLY broadcasts |  | ||||||
|         with patch('bookwyrm.models.activitypub_mixin.broadcast_task.delay') \ |         with patch('bookwyrm.models.activitypub_mixin.broadcast_task.delay') \ | ||||||
|                 as mock: |                 as mock: | ||||||
|             views.unfollow(request) |             views.unfollow(request) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user