mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-25 11:01:12 +00:00
parent
c4549e9b17
commit
e0e419a757
3 changed files with 25 additions and 17 deletions
|
@ -16,7 +16,7 @@ def get_recipients(user, post_privacy, direct_recipients=None):
|
|||
recipients = direct_recipients or []
|
||||
if post_privacy == 'direct':
|
||||
# all we care about is direct_recipients, not followers
|
||||
return recipients
|
||||
return [u.inbox for u in recipients]
|
||||
|
||||
# load all the followers of the user who is sending the message
|
||||
followers = user.followers.all()
|
||||
|
|
|
@ -8,13 +8,12 @@ from django.http import HttpResponse, HttpResponseBadRequest, \
|
|||
from django.views.decorators.csrf import csrf_exempt
|
||||
import json
|
||||
import requests
|
||||
from uuid import uuid4
|
||||
|
||||
from fedireads import models
|
||||
from fedireads.remote_user import get_or_create_remote_user
|
||||
from fedireads import outgoing
|
||||
from fedireads.openlibrary import get_or_create_book
|
||||
from fedireads.remote_user import get_or_create_remote_user
|
||||
from fedireads.sanitize_html import InputHtmlParser
|
||||
from fedireads.settings import DOMAIN
|
||||
|
||||
|
||||
def webfinger(request):
|
||||
|
@ -259,25 +258,16 @@ def handle_incoming_follow(activity):
|
|||
to_follow = models.User.objects.get(actor=activity['object'])
|
||||
# figure out who they are
|
||||
user = get_or_create_remote_user(activity['actor'])
|
||||
to_follow.followers.add(user)
|
||||
# verify uuid and accept the request
|
||||
models.FollowActivity(
|
||||
uuid=activity['id'],
|
||||
user=user,
|
||||
followed=to_follow,
|
||||
content=activity,
|
||||
activity_type='Follow',
|
||||
)
|
||||
uuid = uuid4()
|
||||
# TODO does this need to be signed?
|
||||
# TODO: handle users who moderate followers instead of auto-accepting
|
||||
return JsonResponse({
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
'id': 'https://%s/%s' % (DOMAIN, uuid),
|
||||
'type': 'Accept',
|
||||
'actor': user.actor,
|
||||
'object': activity,
|
||||
})
|
||||
# TODO: allow users to manually approve requests
|
||||
outgoing.handle_outgoing_accept(user, to_follow, activity)
|
||||
return HttpResponse()
|
||||
|
||||
|
||||
|
||||
def handle_incoming_follow_accept(activity):
|
||||
|
|
|
@ -108,6 +108,24 @@ def handle_outgoing_follow(user, to_follow):
|
|||
raise(error['error'])
|
||||
|
||||
|
||||
def handle_outgoing_accept(user, to_follow, activity):
|
||||
''' send an acceptance message to a follow request '''
|
||||
to_follow.followers.add(user)
|
||||
activity = {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
'id': 'https://%s/%s#accepts/follows/' % (DOMAIN, to_follow.localname),
|
||||
'type': 'Accept',
|
||||
'actor': to_follow.actor,
|
||||
'object': activity,
|
||||
}
|
||||
recipient = get_recipients(
|
||||
to_follow,
|
||||
'direct',
|
||||
direct_recipients=[user]
|
||||
)
|
||||
broadcast(to_follow, activity, recipient)
|
||||
|
||||
|
||||
def handle_shelve(user, book, shelf):
|
||||
''' a local user is getting a book put on their shelf '''
|
||||
# update the database
|
||||
|
|
Loading…
Reference in a new issue