diff options
author | Andrew Godwin | 2022-11-10 23:42:43 -0700 |
---|---|---|
committer | Andrew Godwin | 2022-11-10 23:42:43 -0700 |
commit | fbfad9fbf5e061cb7c658dada3c4014c9796021c (patch) | |
tree | 41cb9c3685e347d506876e18c8e535e3d126f1d9 /users/tasks | |
parent | 2c3a1299709f2612e96c37e4e121c83ad4df7a56 (diff) | |
download | takahe-fbfad9fbf5e061cb7c658dada3c4014c9796021c.tar.gz takahe-fbfad9fbf5e061cb7c658dada3c4014c9796021c.tar.bz2 takahe-fbfad9fbf5e061cb7c658dada3c4014c9796021c.zip |
Inbound and outbound follows basic working
Diffstat (limited to 'users/tasks')
-rw-r--r-- | users/tasks/__init__.py | 0 | ||||
-rw-r--r-- | users/tasks/follow.py | 62 |
2 files changed, 0 insertions, 62 deletions
diff --git a/users/tasks/__init__.py b/users/tasks/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/users/tasks/__init__.py +++ /dev/null diff --git a/users/tasks/follow.py b/users/tasks/follow.py deleted file mode 100644 index 0f802cf..0000000 --- a/users/tasks/follow.py +++ /dev/null @@ -1,62 +0,0 @@ -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 - ) - if response.status_code >= 400: - raise ValueError(f"Request error: {response.status_code} {response.content}") - await Follow.objects.filter(pk=follow.pk).aupdate(requested=True) - - -def send_follow_undo(id): - """ - Request a follow from a remote server - """ - follow = Follow.objects.select_related("source", "source__domain", "target").get( - pk=id - ) - # Construct the request - request = canonicalise( - { - "@context": "https://www.w3.org/ns/activitystreams", - "id": follow.uri + "#undo", - "type": "Undo", - "actor": follow.source.actor_uri, - "object": { - "id": follow.uri, - "type": "Follow", - "actor": follow.source.actor_uri, - "object": follow.target.actor_uri, - }, - } - ) - # Sign it and send it - from asgiref.sync import async_to_sync - - response = async_to_sync(HttpSignature.signed_request)( - follow.target.inbox_uri, request, follow.source - ) - if response.status_code >= 400: - raise ValueError(f"Request error: {response.status_code} {response.content}") - print(response) |