forked from mirrors/bookwyrm
Update follow and unfollow to use UserFollowRequest & UserFollows.
This commit is contained in:
parent
e050704c2c
commit
b21c5fc98f
4 changed files with 20 additions and 10 deletions
|
@ -201,10 +201,9 @@ def handle_incoming_follow(activity):
|
|||
user = get_or_create_remote_user(activity['actor'])
|
||||
# TODO: allow users to manually approve requests
|
||||
try:
|
||||
models.UserRelationship.objects.create(
|
||||
models.UserFollowRequest.objects.create(
|
||||
user_subject=user,
|
||||
user_object=to_follow,
|
||||
status='follow_request',
|
||||
relationship_id=activity['id']
|
||||
)
|
||||
except django.db.utils.IntegrityError:
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
from .book import Book, Work, Edition, Author
|
||||
from .shelf import Shelf, ShelfBook
|
||||
from .status import Status, Review, Favorite, Tag, Notification
|
||||
from .user import User, UserRelationship, FederatedServer
|
||||
from .user import User, FederatedServer, UserFollows, UserFollowRequest, UserBlocks
|
||||
|
|
|
@ -109,6 +109,14 @@ class UserFollows(UserRelationship):
|
|||
def status(self):
|
||||
return 'follows'
|
||||
|
||||
@classmethod
|
||||
def from_request(cls, follow_request):
|
||||
return cls(
|
||||
user_subject=follow_request.user_subject,
|
||||
user_object=follow_request.user_object,
|
||||
relationship_id=follow_request.relationship_id,
|
||||
)
|
||||
|
||||
class UserFollowRequest(UserRelationship):
|
||||
@property
|
||||
def status(self):
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
''' handles all the activity coming out of the server '''
|
||||
from django.db import IntegrityError
|
||||
from django.db import IntegrityError, transaction
|
||||
from django.http import HttpResponseNotFound, JsonResponse
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
import requests
|
||||
|
@ -88,7 +88,7 @@ def handle_outgoing_follow(user, to_follow):
|
|||
|
||||
def handle_outgoing_unfollow(user, to_unfollow):
|
||||
''' someone local wants to follow someone '''
|
||||
relationship = models.UserRelationship.objects.get(
|
||||
relationship = models.UserFollows.objects.get(
|
||||
user_subject=user,
|
||||
user_object=to_unfollow
|
||||
)
|
||||
|
@ -101,11 +101,14 @@ def handle_outgoing_unfollow(user, to_unfollow):
|
|||
|
||||
def handle_outgoing_accept(user, to_follow, request_activity):
|
||||
''' send an acceptance message to a follow request '''
|
||||
relationship = models.UserRelationship.objects.get(
|
||||
relationship_id=request_activity['id']
|
||||
)
|
||||
relationship.status = 'follow'
|
||||
relationship.save()
|
||||
with transaction.atomic():
|
||||
follow_request = models.UserFollowRequest.objects.get(
|
||||
relationship_id=request_activity['id']
|
||||
)
|
||||
relationship = models.UserFollows.from_request(follow_request)
|
||||
follow_request.delete()
|
||||
relationship.save()
|
||||
|
||||
activity = activitypub.get_accept(to_follow, request_activity)
|
||||
recipient = get_recipients(to_follow, 'direct', direct_recipients=[user])
|
||||
broadcast(to_follow, activity, recipient)
|
||||
|
|
Loading…
Reference in a new issue