mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-24 00:50:35 +00:00
Simplifies outgoing follow logic
This commit is contained in:
parent
694de44f3f
commit
a567bd4e61
4 changed files with 23 additions and 4 deletions
|
@ -143,7 +143,7 @@ def handle_follow(activity):
|
|||
'FOLLOW',
|
||||
related_user=actor
|
||||
)
|
||||
outgoing.handle_accept(actor, to_follow, relationship)
|
||||
outgoing.handle_accept(relationship)
|
||||
else:
|
||||
# Accept will be triggered manually
|
||||
status_builder.create_notification(
|
||||
|
|
|
@ -80,8 +80,10 @@ def handle_unfollow(user, to_unfollow):
|
|||
to_unfollow.followers.remove(user)
|
||||
|
||||
|
||||
def handle_accept(user, to_follow, follow_request):
|
||||
def handle_accept(follow_request):
|
||||
''' send an acceptance message to a follow request '''
|
||||
user = follow_request.user_subject
|
||||
to_follow = follow_request.user_object
|
||||
with transaction.atomic():
|
||||
relationship = models.UserFollows.from_request(follow_request)
|
||||
follow_request.delete()
|
||||
|
|
|
@ -3,7 +3,7 @@ from django.test import TestCase
|
|||
from bookwyrm import models, outgoing
|
||||
|
||||
|
||||
class OutgoingFollow(TestCase):
|
||||
class Following(TestCase):
|
||||
def setUp(self):
|
||||
self.remote_user = models.User.objects.create_user(
|
||||
'rat', 'rat@rat.com', 'ratword',
|
||||
|
@ -29,9 +29,26 @@ class OutgoingFollow(TestCase):
|
|||
self.assertEqual(rel.user_object, self.remote_user)
|
||||
self.assertEqual(rel.status, 'follow_request')
|
||||
|
||||
|
||||
def test_handle_unfollow(self):
|
||||
self.remote_user.followers.add(self.local_user)
|
||||
self.assertEqual(self.remote_user.followers.count(), 1)
|
||||
outgoing.handle_unfollow(self.local_user, self.remote_user)
|
||||
|
||||
self.assertEqual(self.remote_user.followers.count(), 0)
|
||||
|
||||
|
||||
def test_handle_accept(self):
|
||||
rel = models.UserFollowRequest.objects.create(
|
||||
user_subject=self.local_user,
|
||||
user_object=self.remote_user
|
||||
)
|
||||
rel_id = rel.id
|
||||
|
||||
outgoing.handle_accept(rel)
|
||||
# request should be deleted
|
||||
self.assertEqual(
|
||||
models.UserFollowRequest.objects.filter(id=rel_id).count(), 0
|
||||
)
|
||||
# follow relationship should exist
|
||||
self.assertEqual(self.remote_user.followers.first(), self.local_user)
|
||||
|
|
|
@ -473,7 +473,7 @@ def accept_follow_request(request):
|
|||
# Request already dealt with.
|
||||
pass
|
||||
else:
|
||||
outgoing.handle_accept(requester, request.user, follow_request)
|
||||
outgoing.handle_accept(follow_request)
|
||||
|
||||
return redirect('/user/%s' % request.user.localname)
|
||||
|
||||
|
|
Loading…
Reference in a new issue