mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-23 06:58:58 +00:00
user: refactor get_or_create_instance_user() into get_or_create_service_actor_by_id()
This commit is contained in:
parent
ce73d5f6a5
commit
4885473be2
|
@ -1157,19 +1157,18 @@ defmodule Pleroma.User do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_or_create_instance_user do
|
@doc "Creates an internal service actor by URI if missing. Optionally takes nickname for addressing."
|
||||||
relay_uri = "#{Pleroma.Web.Endpoint.url()}/relay"
|
def get_or_create_service_actor_by_ap_id(uri, nickname \\ nil) do
|
||||||
|
if user = get_cached_by_ap_id(uri) do
|
||||||
if user = get_cached_by_ap_id(relay_uri) do
|
|
||||||
user
|
user
|
||||||
else
|
else
|
||||||
changes =
|
changes =
|
||||||
%User{info: %User.Info{}}
|
%User{info: %User.Info{}}
|
||||||
|> cast(%{}, [:ap_id, :nickname, :local])
|
|> cast(%{}, [:ap_id, :nickname, :local])
|
||||||
|> put_change(:ap_id, relay_uri)
|
|> put_change(:ap_id, uri)
|
||||||
|> put_change(:nickname, nil)
|
|> put_change(:nickname, nickname)
|
||||||
|> put_change(:local, true)
|
|> put_change(:local, true)
|
||||||
|> put_change(:follower_address, relay_uri <> "/followers")
|
|> put_change(:follower_address, uri <> "/followers")
|
||||||
|
|
||||||
{:ok, user} = Repo.insert(changes)
|
{:ok, user} = Repo.insert(changes)
|
||||||
user
|
user
|
||||||
|
|
|
@ -10,7 +10,8 @@ defmodule Pleroma.Web.ActivityPub.Relay do
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
def get_actor do
|
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
|
end
|
||||||
|
|
||||||
def follow(target_instance) do
|
def follow(target_instance) do
|
||||||
|
|
Loading…
Reference in a new issue