Commit b5267229 authored by lain's avatar lain

Move incoming AP to Federator.

parent 391b3e35
Pipeline #778 failed with stage
in 1 minute and 30 seconds
......@@ -3,6 +3,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
alias Pleroma.{User, Repo, Object, Activity}
alias Pleroma.Web.ActivityPub.{ObjectView, UserView, Transmogrifier}
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.Federator
require Logger
......@@ -24,22 +25,8 @@ def object(conn, %{"uuid" => uuid}) do
# TODO: Ensure that this inbox is a recipient of the message
def inbox(%{assigns: %{valid_signature: true}} = conn, params) do
# File.write("/tmp/incoming.json", Poison.encode!(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")
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
Federator.enqeue(:incoming_ap_doc, params)
json(conn, "ok")
end
def inbox(conn, params) do
......@@ -48,15 +35,6 @@ def inbox(conn, params) do
json(conn, "ok")
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
conn
|> put_status(500)
......
......@@ -3,6 +3,7 @@ defmodule Pleroma.Web.Federator do
alias Pleroma.User
alias Pleroma.Web.{WebFinger, Websub}
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Transmogrifier
require Logger
@websub Application.get_env(:pleroma, :websub)
......@@ -66,6 +67,20 @@ def handle(:incoming_doc, doc) do
@ostatus.handle_incoming(doc)
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
ActivityPub.publish_one(params)
end
......@@ -145,4 +160,13 @@ def enqueue_sorted(queue, element, priority) do
def queue_pop([%{item: element} | queue]) do
{element, queue}
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment