From 4807a52284250e1663da0ba31c57a0c05861b797 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 6 Aug 2018 05:46:37 +0000 Subject: [PATCH] user: support creating an actor which represents the instance itself --- lib/pleroma/user.ex | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index df22d29a8..640c34aec 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -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}} -- 2.45.2