summaryrefslogtreecommitdiffstats
path: root/users/tasks
diff options
context:
space:
mode:
authorAndrew Godwin2022-11-08 23:06:29 -0700
committerAndrew Godwin2022-11-09 22:29:49 -0700
commit61c324508e62bb640b4526183d0837fc57d742c2 (patch)
tree618ee8c88ce8a28224a187dc33b7c5fad6831d04 /users/tasks
parent8a0a7558894afce8d25b7f0dc16775e899b72a94 (diff)
downloadtakahe-61c324508e62bb640b4526183d0837fc57d742c2.tar.gz
takahe-61c324508e62bb640b4526183d0837fc57d742c2.tar.bz2
takahe-61c324508e62bb640b4526183d0837fc57d742c2.zip
Midway point in task refactor - changing direction
Diffstat (limited to 'users/tasks')
-rw-r--r--users/tasks/follow.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/users/tasks/follow.py b/users/tasks/follow.py
index 872b35f..0f802cf 100644
--- a/users/tasks/follow.py
+++ b/users/tasks/follow.py
@@ -27,3 +27,36 @@ async def handle_follow_request(task_handler):
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)