summaryrefslogtreecommitdiffstats
path: root/users/tasks
diff options
context:
space:
mode:
authorAndrew Godwin2022-11-09 23:48:31 -0700
committerAndrew Godwin2022-11-09 23:48:31 -0700
commit2c3a1299709f2612e96c37e4e121c83ad4df7a56 (patch)
tree89c2aed22a7a10730e02c809f83b744a21e295e1 /users/tasks
parent7746abbbb7700fa918450101bbc6d29ed9b4b608 (diff)
downloadtakahe-2c3a1299709f2612e96c37e4e121c83ad4df7a56.tar.gz
takahe-2c3a1299709f2612e96c37e4e121c83ad4df7a56.tar.bz2
takahe-2c3a1299709f2612e96c37e4e121c83ad4df7a56.zip
Profile fetching now working on state machine
Diffstat (limited to 'users/tasks')
-rw-r--r--users/tasks/identity.py11
-rw-r--r--users/tasks/inbox.py56
2 files changed, 0 insertions, 67 deletions
diff --git a/users/tasks/identity.py b/users/tasks/identity.py
deleted file mode 100644
index f5cd214..0000000
--- a/users/tasks/identity.py
+++ /dev/null
@@ -1,11 +0,0 @@
-from asgiref.sync import sync_to_async
-
-from users.models import Identity
-
-
-async def handle_identity_fetch(task_handler):
- # Get the actor URI via webfinger
- actor_uri, handle = await Identity.fetch_webfinger(task_handler.subject)
- # Get or create the identity, then fetch
- identity = await sync_to_async(Identity.by_actor_uri_with_create)(actor_uri)
- await identity.fetch_actor()
diff --git a/users/tasks/inbox.py b/users/tasks/inbox.py
deleted file mode 100644
index 27c602d..0000000
--- a/users/tasks/inbox.py
+++ /dev/null
@@ -1,56 +0,0 @@
-from asgiref.sync import sync_to_async
-
-from users.models import Follow, Identity
-
-
-async def handle_inbox_item(task_handler):
- type = task_handler.payload["type"].lower()
- if type == "follow":
- await inbox_follow(task_handler.payload)
- elif type == "accept":
- inner_type = task_handler.payload["object"]["type"].lower()
- if inner_type == "follow":
- await sync_to_async(accept_follow)(task_handler.payload["object"])
- else:
- raise ValueError(f"Cannot handle activity of type accept.{inner_type}")
- elif type == "undo":
- inner_type = task_handler.payload["object"]["type"].lower()
- if inner_type == "follow":
- await inbox_unfollow(task_handler.payload["object"])
- else:
- raise ValueError(f"Cannot handle activity of type undo.{inner_type}")
- else:
- raise ValueError(f"Cannot handle activity of type {inner_type}")
-
-
-async def inbox_follow(payload):
- """
- Handles an incoming follow request
- """
- # TODO: Manually approved follows
- source = Identity.by_actor_uri_with_create(payload["actor"])
- target = Identity.by_actor_uri(payload["object"])
- # See if this follow already exists
- try:
- follow = Follow.objects.get(source=source, target=target)
- except Follow.DoesNotExist:
- follow = Follow.objects.create(source=source, target=target, uri=payload["id"])
- # See if we need to acknowledge it
- if not follow.acknowledged:
- pass
-
-
-async def inbox_unfollow(payload):
- pass
-
-
-def accept_follow(payload):
- """
- Another server has acknowledged our follow request
- """
- source = Identity.by_actor_uri_with_create(payload["actor"])
- target = Identity.by_actor_uri(payload["object"])
- follow = Follow.maybe_get(source, target)
- if follow:
- follow.accepted = True
- follow.save()