Move incoming AP to Federator.
This commit is contained in:
parent
391b3e3586
commit
b52672294e
|
@ -3,6 +3,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
|
||||||
alias Pleroma.{User, Repo, Object, Activity}
|
alias Pleroma.{User, Repo, Object, Activity}
|
||||||
alias Pleroma.Web.ActivityPub.{ObjectView, UserView, Transmogrifier}
|
alias Pleroma.Web.ActivityPub.{ObjectView, UserView, Transmogrifier}
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
|
alias Pleroma.Web.Federator
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
|
@ -24,22 +25,8 @@ def object(conn, %{"uuid" => uuid}) do
|
||||||
|
|
||||||
# TODO: Ensure that this inbox is a recipient of the message
|
# TODO: Ensure that this inbox is a recipient of the message
|
||||||
def inbox(%{assigns: %{valid_signature: true}} = conn, params) do
|
def inbox(%{assigns: %{valid_signature: true}} = conn, params) do
|
||||||
# File.write("/tmp/incoming.json", Poison.encode!(params))
|
Federator.enqeue(:incoming_ap_doc, params)
|
||||||
# Logger.info(Poison.encode!(params, [pretty: 2]))
|
|
||||||
with {:ok, _user} <- ap_enabled_actor(params["actor"]),
|
|
||||||
nil <- Activity.get_by_ap_id(params["id"]),
|
|
||||||
{:ok, activity} <- Transmogrifier.handle_incoming(params) do
|
|
||||||
json(conn, "ok")
|
json(conn, "ok")
|
||||||
else
|
|
||||||
%Activity{} ->
|
|
||||||
Logger.info("Already had #{params["id"]}")
|
|
||||||
json(conn, "ok")
|
|
||||||
e ->
|
|
||||||
# Just drop those for now
|
|
||||||
Logger.info("Unhandled activity")
|
|
||||||
Logger.info(Poison.encode!(params, [pretty: 2]))
|
|
||||||
json(conn, "ok")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def inbox(conn, params) do
|
def inbox(conn, params) do
|
||||||
|
@ -48,15 +35,6 @@ def inbox(conn, params) do
|
||||||
json(conn, "ok")
|
json(conn, "ok")
|
||||||
end
|
end
|
||||||
|
|
||||||
def ap_enabled_actor(id) do
|
|
||||||
user = User.get_by_ap_id(id)
|
|
||||||
if User.ap_enabled?(user) do
|
|
||||||
{:ok, user}
|
|
||||||
else
|
|
||||||
ActivityPub.make_user_from_ap_id(id)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def errors(conn, _e) do
|
def errors(conn, _e) do
|
||||||
conn
|
conn
|
||||||
|> put_status(500)
|
|> put_status(500)
|
||||||
|
|
|
@ -3,6 +3,7 @@ defmodule Pleroma.Web.Federator do
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.{WebFinger, Websub}
|
alias Pleroma.Web.{WebFinger, Websub}
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
|
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
@websub Application.get_env(:pleroma, :websub)
|
@websub Application.get_env(:pleroma, :websub)
|
||||||
|
@ -66,6 +67,20 @@ def handle(:incoming_doc, doc) do
|
||||||
@ostatus.handle_incoming(doc)
|
@ostatus.handle_incoming(doc)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def handle(:incoming_ap_doc, params) do
|
||||||
|
with {:ok, _user} <- ap_enabled_actor(params["actor"]),
|
||||||
|
nil <- Activity.get_by_ap_id(params["id"]),
|
||||||
|
{:ok, activity} <- Transmogrifier.handle_incoming(params) do
|
||||||
|
else
|
||||||
|
%Activity{} ->
|
||||||
|
Logger.info("Already had #{params["id"]}")
|
||||||
|
e ->
|
||||||
|
# Just drop those for now
|
||||||
|
Logger.info("Unhandled activity")
|
||||||
|
Logger.info(Poison.encode!(params, [pretty: 2]))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def handle(:publish_single_ap, params) do
|
def handle(:publish_single_ap, params) do
|
||||||
ActivityPub.publish_one(params)
|
ActivityPub.publish_one(params)
|
||||||
end
|
end
|
||||||
|
@ -145,4 +160,13 @@ def enqueue_sorted(queue, element, priority) do
|
||||||
def queue_pop([%{item: element} | queue]) do
|
def queue_pop([%{item: element} | queue]) do
|
||||||
{element, queue}
|
{element, queue}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ap_enabled_actor(id) do
|
||||||
|
user = User.get_by_ap_id(id)
|
||||||
|
if User.ap_enabled?(user) do
|
||||||
|
{:ok, user}
|
||||||
|
else
|
||||||
|
ActivityPub.make_user_from_ap_id(id)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue