From 398297712158f0f7a9a8349a03a802011c078fe4 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 6 May 2022 16:58:33 +0200 Subject: [PATCH] Allow to get Mastodon instance relays Signed-off-by: Thomas Citharel --- lib/graphql/resolvers/admin.ex | 2 +- lib/mobilizon/actors/actors.ex | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/graphql/resolvers/admin.ex b/lib/graphql/resolvers/admin.ex index 43b6a1540..a362fd819 100644 --- a/lib/graphql/resolvers/admin.ex +++ b/lib/graphql/resolvers/admin.ex @@ -469,7 +469,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Admin do }) when is_admin(role) do has_relay = Actors.has_relay?(domain) - remote_relay = Actors.get_actor_by_name("relay@#{domain}") + remote_relay = Actors.get_relay(domain) local_relay = Relay.get_actor() result = %{ diff --git a/lib/mobilizon/actors/actors.ex b/lib/mobilizon/actors/actors.ex index 14d6cb372..5ee184e0f 100644 --- a/lib/mobilizon/actors/actors.ex +++ b/lib/mobilizon/actors/actors.ex @@ -1307,6 +1307,14 @@ defmodule Mobilizon.Actors do |> Repo.exists?() end + @doc """ + Returns a relay actor, either `relay@domain` (Mobilizon) or `domain@domain` (Mastodon) + """ + @spec get_relay(String.t()) :: Actor.t() | nil + def get_relay(domain) do + get_actor_by_name("relay@#{domain}") || get_actor_by_name("#{domain}@#{domain}") + end + @spec delete_files_if_media_changed(Ecto.Changeset.t()) :: Ecto.Changeset.t() defp delete_files_if_media_changed(%Ecto.Changeset{changes: changes, data: data} = changeset) do Enum.each([:avatar, :banner], fn key ->