Update
This commit is contained in:
parent
58049c93d4
commit
894866ca03
22 changed files with 344 additions and 213 deletions
|
@ -1,19 +1,49 @@
|
|||
defmodule NullaWeb.InboxController do
|
||||
use NullaWeb, :controller
|
||||
alias Nulla.Models.Follow
|
||||
alias Nulla.HTTPSignature
|
||||
alias Nulla.ActivityPub
|
||||
alias Nulla.Utils
|
||||
alias Nulla.Models.Actor
|
||||
alias Nulla.Models.Relation
|
||||
|
||||
def inbox(
|
||||
conn,
|
||||
%{"type" => "Follow", "actor" => actor_uri, "object" => target_uri} = activity
|
||||
%{"id" => follow_id, "type" => "Follow", "actor" => actor_uri, "object" => target_uri}
|
||||
) 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"})
|
||||
with {:ok, target_actor} <- Utils.resolve_local_actor(target_uri),
|
||||
{:ok, remote_actor_json} <- Utils.fetch_remote_actor(actor_uri),
|
||||
:ok <- HTTPSignature.verify(conn, remote_actor_json),
|
||||
remote_actor <-
|
||||
Actor.create_actor(
|
||||
remote_actor_json
|
||||
|> Map.put("ap_id", remote_actor_json["id"])
|
||||
|> Map.delete("id")
|
||||
|> Map.put("domain", URI.parse(remote_actor_json["id"]).host)
|
||||
),
|
||||
follow_activity <-
|
||||
Activity.create_activity(%{
|
||||
ap_id: follow_id,
|
||||
type: "Follow",
|
||||
actor: actor_uri,
|
||||
object: target_uri
|
||||
}),
|
||||
accept_activity <-
|
||||
Activity.create_activity(%{
|
||||
type: "Accept",
|
||||
actor: target_uri,
|
||||
object: follow_activity
|
||||
}),
|
||||
relation <- Relation.create_relation(%{
|
||||
id: 1,
|
||||
follower: remote_actor.id,
|
||||
followed: target_actor.id
|
||||
}) do
|
||||
conn
|
||||
|> put_resp_content_type("application/activity+json")
|
||||
|> send_resp(
|
||||
200,
|
||||
Jason.encode!(ActivityPub.follow_accept(accept_activity))
|
||||
)
|
||||
else
|
||||
error ->
|
||||
IO.inspect(error, label: "Follow error")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue