Inbox: Don't add the same thing twice.

This commit is contained in:
lain 2018-02-18 22:37:44 +01:00
parent 010f818a29
commit 76e71f47d3

View file

@ -1,6 +1,6 @@
defmodule Pleroma.Web.ActivityPub.ActivityPubController do defmodule Pleroma.Web.ActivityPub.ActivityPubController do
use Pleroma.Web, :controller use Pleroma.Web, :controller
alias Pleroma.{User, Repo, Object} 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
@ -26,9 +26,13 @@ def object(conn, %{"uuid" => uuid}) do
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)) # File.write("/tmp/incoming.json", Poison.encode!(params))
with {:ok, _user} <- ap_enabled_actor(params["actor"]), with {:ok, _user} <- ap_enabled_actor(params["actor"]),
nil <- Activity.get_by_ap_id(params["id"]),
{:ok, activity} <- Transmogrifier.handle_incoming(params) do {:ok, activity} <- Transmogrifier.handle_incoming(params) do
json(conn, "ok") json(conn, "ok")
else else
%Activity{} ->
Logger.info("Already had #{params["id"]}")
json(conn, "ok")
e -> e ->
# Just drop those for now # Just drop those for now
Logger.info("Unhandled activity") Logger.info("Unhandled activity")