user: refactor get_or_create_instance_user() into get_or_create_service_actor_by_id()
authorAriadne Conill <ariadne@dereferenced.org>
Wed, 17 Jul 2019 15:48:51 +0000 (15:48 +0000)
committerAriadne Conill <ariadne@dereferenced.org>
Wed, 17 Jul 2019 16:03:05 +0000 (16:03 +0000)
lib/pleroma/user.ex
lib/pleroma/web/activity_pub/relay.ex

index ffba3f3903912e343b61ccdef045225196b02600..463bb9ad44162cebb66534c6213ff0a74f26d07a 100644 (file)
@@ -1157,19 +1157,18 @@ defmodule Pleroma.User do
     end
   end
 
-  def get_or_create_instance_user do
-    relay_uri = "#{Pleroma.Web.Endpoint.url()}/relay"
-
-    if user = get_cached_by_ap_id(relay_uri) do
+  @doc "Creates an internal service actor by URI if missing.  Optionally takes nickname for addressing."
+  def get_or_create_service_actor_by_ap_id(uri, nickname \\ nil) do
+    if user = get_cached_by_ap_id(uri) do
       user
     else
       changes =
         %User{info: %User.Info{}}
         |> cast(%{}, [:ap_id, :nickname, :local])
-        |> put_change(:ap_id, relay_uri)
-        |> put_change(:nickname, nil)
+        |> put_change(:ap_id, uri)
+        |> put_change(:nickname, nickname)
         |> put_change(:local, true)
-        |> put_change(:follower_address, relay_uri <> "/followers")
+        |> put_change(:follower_address, uri <> "/followers")
 
       {:ok, user} = Repo.insert(changes)
       user
index 93808517bde9ad2af6c717de8022b0db9c513a7c..1ebfcdd86a67743c3e69b945772f762d2c79e6ed 100644 (file)
@@ -10,7 +10,8 @@ defmodule Pleroma.Web.ActivityPub.Relay do
   require Logger
 
   def get_actor do
-    User.get_or_create_instance_user()
+    "#{Pleroma.Web.Endpoint.url()}/relay"
+    |> User.get_or_create_service_actor_by_ap_id()
   end
 
   def follow(target_instance) do