From fb6c409a9af5b8a686e977ee2251c359071e0ec3 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Sun, 6 Nov 2022 21:30:07 -0700 Subject: Rework task system and fetching. I can taste how close follow is to working. --- users/tasks/follow.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 users/tasks/follow.py (limited to 'users/tasks/follow.py') diff --git a/users/tasks/follow.py b/users/tasks/follow.py new file mode 100644 index 0000000..3260124 --- /dev/null +++ b/users/tasks/follow.py @@ -0,0 +1,28 @@ +from core.ld import canonicalise +from core.signatures import HttpSignature +from users.models import Follow + + +async def handle_follow_request(task_handler): + """ + Request a follow from a remote server + """ + follow = await Follow.objects.select_related( + "source", "source__domain", "target" + ).aget(pk=task_handler.subject) + # Construct the request + request = canonicalise( + { + "@context": "https://www.w3.org/ns/activitystreams", + "id": follow.uri, + "type": "Follow", + "actor": follow.source.actor_uri, + "object": follow.target.actor_uri, + } + ) + # Sign it and send it + response = await HttpSignature.signed_request( + follow.target.inbox_uri, request, follow.source + ) + print(response) + print(response.content) -- cgit v1.2.3