mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-02-02 20:32:20 +00:00
Add user to database on accept
This commit is contained in:
parent
f03f370f60
commit
dae9b5c023
1 changed files with 19 additions and 2 deletions
|
@ -89,6 +89,7 @@ def inbox(request, username):
|
||||||
|
|
||||||
if activity['type'] == 'Create':
|
if activity['type'] == 'Create':
|
||||||
return handle_incoming_create(activity)
|
return handle_incoming_create(activity)
|
||||||
|
|
||||||
return HttpResponse()
|
return HttpResponse()
|
||||||
|
|
||||||
|
|
||||||
|
@ -187,10 +188,25 @@ def handle_outgoing_follow(user, to_follow):
|
||||||
}
|
}
|
||||||
|
|
||||||
broadcast(user, activity, [format_inbox(to_follow)])
|
broadcast(user, activity, [format_inbox(to_follow)])
|
||||||
|
|
||||||
|
def handle_response(response):
|
||||||
|
''' hopefully it's an accept from our follow request '''
|
||||||
|
activity = response.json()
|
||||||
|
if not activity:
|
||||||
|
return
|
||||||
|
if activity['type'] == 'Accept':
|
||||||
|
handle_incoming_accept(activity)
|
||||||
|
|
||||||
|
def handle_incoming_accept(activity):
|
||||||
|
''' someone is accepting a follow request '''
|
||||||
|
# remote user who said yes
|
||||||
|
user = get_or_create_remote_user(activity['actor'])
|
||||||
|
followed = models.User.objects.get(actor=activity['object']['actor'])
|
||||||
|
followed.followers.add(user)
|
||||||
models.FollowActivity(
|
models.FollowActivity(
|
||||||
uuid=uuid,
|
uuid=activity['id'],
|
||||||
user=user,
|
user=user,
|
||||||
followed=to_follow,
|
followed=followed,
|
||||||
content=activity,
|
content=activity,
|
||||||
).save()
|
).save()
|
||||||
|
|
||||||
|
@ -367,6 +383,7 @@ date: %s''' % (inbox_fragment, DOMAIN, now)
|
||||||
)
|
)
|
||||||
if not response.ok:
|
if not response.ok:
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
handle_response(response)
|
||||||
|
|
||||||
|
|
||||||
def get_or_create_remote_user(actor):
|
def get_or_create_remote_user(actor):
|
||||||
|
|
Loading…
Reference in a new issue