forked from YokaiRick/akkoma
Move incoming AP to Federator.
This commit is contained in:
parent
391b3e3586
commit
b52672294e
2 changed files with 27 additions and 25 deletions
|
@ -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
|
||||
Federator.enqeue(:incoming_ap_doc, params)
|
||||
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
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue