alias Pleroma.Web.ActivityPub.{ObjectView, UserView}
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Relay
+ alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.Federator
require Logger
action_fallback(:errors)
+ plug(Pleroma.Web.FederatingPlug when action in [:inbox, :relay])
+ plug(:relay_active? when action in [:relay])
+
+ def relay_active?(conn, _) do
+ if Keyword.get(Application.get_env(:pleroma, :instance), :allow_relay) do
+ conn
+ else
+ conn
+ |> put_status(404)
+ |> json(%{error: "not found"})
+ |> halt
+ end
+ end
+
def user(conn, %{"nickname" => nickname}) do
with %User{} = user <- User.get_cached_by_nickname(nickname),
{:ok, user} <- Pleroma.Web.WebFinger.ensure_keys_present(user) do
outbox(conn, %{"nickname" => nickname, "max_id" => nil})
end
- # TODO: Ensure that this inbox is a recipient of the message
+ def inbox(%{assigns: %{valid_signature: true}} = conn, %{"nickname" => nickname} = params) do
+ with %User{} = user <- User.get_cached_by_nickname(nickname),
+ true <- Utils.recipient_in_message(user.ap_id, params),
+ params <- Utils.maybe_splice_recipient(user.ap_id, params) do
+ Federator.enqueue(:incoming_ap_doc, params)
+ json(conn, "ok")
+ end
+ end
+
def inbox(%{assigns: %{valid_signature: true}} = conn, params) do
Federator.enqueue(:incoming_ap_doc, params)
json(conn, "ok")