defmodule NullaWeb.InboxController do use NullaWeb, :controller alias Nulla.Models.Follow alias Nulla.Utils 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