Switch protocols to AP when post come in through AP.
authorlain <lain@soykaf.club>
Sun, 18 Feb 2018 11:04:59 +0000 (12:04 +0100)
committerlain <lain@soykaf.club>
Sun, 18 Feb 2018 11:04:59 +0000 (12:04 +0100)
lib/pleroma/user.ex
lib/pleroma/web/activity_pub/activity_pub_controller.ex

index ab29fe6f452f352a3a83d6a325cb4cf724d9aaff..2ca4d406b4dc8b48d7890de084c715ebcfbd1908 100644 (file)
@@ -427,5 +427,5 @@ defmodule Pleroma.User do
     Repo.insert(cs, on_conflict: :replace_all, conflict_target: :nickname)
   end
 
-  def ap_enabled?(%User{info: %{"ap_enabled" => ap}}), do: ap
+  def ap_enabled?(%User{info: info}), do: info["ap_enabled"]
 end
index a4472a8329667614f342d788091d0ee9abd0566c..8080a2b1e5afcd8f5e566ca0345c650a4e378f4c 100644 (file)
@@ -23,13 +23,23 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController 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))
-    with {:ok, activity} <- Transmogrifier.handle_incoming(params) do
+    with {:ok, _user} <- ap_enabled_actor(params["actor"]),
+         {:ok, activity} <- Transmogrifier.handle_incoming(params) do
       json(conn, "ok")
     else
       e -> IO.inspect(e)
     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
     conn
     |> put_status(500)