Update
This commit is contained in:
parent
b596606c14
commit
58049c93d4
8 changed files with 115 additions and 149 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue