Follow/unfollow behavior

Fixes #23
This commit is contained in:
Mouse Reeve
2020-02-18 22:44:13 -08:00
parent 14d300162d
commit 95bfb61cf3
10 changed files with 138 additions and 102 deletions

View File

@ -37,6 +37,9 @@ def shared_inbox(request):
if activity['type'] == 'Follow':
response = handle_incoming_follow(activity)
elif activity['type'] == 'Undo':
response = handle_incoming_undo(activity)
elif activity['type'] == 'Create':
response = handle_incoming_create(activity)
@ -183,10 +186,32 @@ def handle_incoming_follow(activity):
# figure out who they are
user = get_or_create_remote_user(activity['actor'])
# TODO: allow users to manually approve requests
models.UserRelationship.objects.create(
user_subject=to_follow,
user_object=user,
status='follow_request',
relationship_id=activity['id']
)
outgoing.handle_outgoing_accept(user, to_follow, activity)
return HttpResponse()
def handle_incoming_undo(activity):
''' unfollow a local user '''
obj = activity['object']
if not obj['type'] == 'Follow':
#idk how to undo other things
return HttpResponseNotFound()
try:
requester = get_or_create_remote_user(obj['actor'])
to_unfollow = models.User.objects.get(actor=obj['object'])
except models.User.DoesNotExist:
return HttpResponseNotFound()
to_unfollow.followers.remove(requester)
return HttpResponse()
def handle_incoming_follow_accept(activity):
''' hurray, someone remote accepted a follow request '''
# figure out who they want to follow