This commit is contained in:
Mirai Kumiko 2025-06-15 19:36:03 +02:00
parent b596606c14
commit 58049c93d4
Signed by: miraikumiko
GPG key ID: 3F178B1B5E0CB278
8 changed files with 115 additions and 149 deletions

View file

@ -1,25 +1,23 @@
defmodule NullaWeb.InboxController do
use NullaWeb, :controller
alias Nulla.Models.Follow
alias Nulla.Utils
def receive(conn, %{"type" => "Follow"} = activity) do
# Check signature
# Verify actor and object
# Save follow to db
# Send Accept or Reject
json(conn, %{"status" => "Follow received"})
end
def receive(conn, %{"type" => "Like"} = activity) do
# Process Like
json(conn, %{"status" => "Like received"})
end
def receive(conn, %{"type" => "Create"} = activity) do
# Create object and save
json(conn, %{"status" => "Object created"})
end
def receive(conn, _params) do
json(conn, %{"status" => "Unhandled type"})
def inbox(
conn,
%{"type" => "Follow", "actor" => actor_uri, "object" => target_uri} = activity
) do
with {:ok, target_user} <- Utils.resolve_local_actor(target_uri),
{:ok, remote_actor} <- Utils.fetch_remote_actor(actor_uri),
:ok <- HTTPSignature.verify(conn, remote_actor),
remote_user <- Follow.create_remote_user(remote_actor),
follow <- Follow.create_follow(%{user: remote_user, target: target_user}),
:ok <- Utils.send_accept_activity(remote_actor, target_user, follow, activity) do
json(conn, %{"status" => "Follow accepted"})
else
error ->
IO.inspect(error, label: "Follow error")
json(conn, %{"error" => "Failed to process Follow"})
end
end
end