user: support creating an actor which represents the instance itself
authorWilliam Pitcock <nenolod@dereferenced.org>
Mon, 6 Aug 2018 05:46:37 +0000 (05:46 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Mon, 6 Aug 2018 08:22:07 +0000 (08:22 +0000)
lib/pleroma/user.ex

index df22d29a83f6ea66f45491cb419a2cf94e275b6b..640c34aec5c347606fa4588099856ce9c4abb555 100644 (file)
@@ -637,6 +637,22 @@ defmodule Pleroma.User do
     end
   end
 
+  def get_or_create_instance_user do
+    if user = get_by_ap_id(Pleroma.Web.Endpoint.url()) do
+      user
+    else
+      changes =
+        %User{}
+        |> cast(%{}, [:ap_id, :nickname, :local])
+        |> put_change(:ap_id, Pleroma.Web.Endpoint.url())
+        |> put_change(:nickname, nil)
+        |> put_change(:local, true)
+
+      {:ok, user} = Repo.insert(changes)
+      user
+    end
+  end
+
   # AP style
   def public_key_from_info(%{
         "source_data" => %{"publicKey" => %{"publicKeyPem" => public_key_pem}}