Factorized follow logic between system actors, Library can now accept follows

This commit is contained in:
Eliot Berriot 2018-04-04 19:38:55 +02:00
parent b833a11fb6
commit d8f86c4fce
No known key found for this signature in database
GPG key ID: DD6965E2476E5C27
4 changed files with 145 additions and 66 deletions

View file

@ -2,7 +2,9 @@ import logging
import json
import requests
import requests_http_signature
import uuid
from . import models
from . import signing
logger = logging.getLogger(__name__)
@ -117,3 +119,20 @@ def get_accept_follow(accept_id, accept_actor, follow, follow_actor):
"object": accept_actor.url
},
}
def accept_follow(target, follow, actor):
accept_uuid = uuid.uuid4()
accept = get_accept_follow(
accept_id=accept_uuid,
accept_actor=target,
follow=follow,
follow_actor=actor)
deliver(
accept,
to=[actor.url],
on_behalf_of=target)
return models.Follow.objects.get_or_create(
actor=actor,
target=target,
)