From 85a8a68fd600ccefb733f1be514b4ea6c144c1bf Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 21 Oct 2020 11:02:28 +0200 Subject: [PATCH] Add task to refresh an instance relay Signed-off-by: Thomas Citharel --- lib/federation/activity_pub/relay.ex | 11 ++++++++++- lib/mix/tasks/mobilizon/relay.ex | 13 +++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/federation/activity_pub/relay.ex b/lib/federation/activity_pub/relay.ex index 0fd5b83d4..13a8b2f12 100644 --- a/lib/federation/activity_pub/relay.ex +++ b/lib/federation/activity_pub/relay.ex @@ -12,7 +12,7 @@ defmodule Mobilizon.Federation.ActivityPub.Relay do alias Mobilizon.Actors.{Actor, Follower} alias Mobilizon.Federation.ActivityPub - alias Mobilizon.Federation.ActivityPub.{Activity, Transmogrifier} + alias Mobilizon.Federation.ActivityPub.{Activity, Refresher, Transmogrifier} alias Mobilizon.Federation.WebFinger alias Mobilizon.GraphQL.API.Follows @@ -90,6 +90,15 @@ defmodule Mobilizon.Federation.ActivityPub.Relay do end end + def refresh(address) do + Logger.debug("We're trying to refresh a remote instance") + + with {:ok, target_instance} <- fetch_actor(address), + {:ok, %Actor{} = target_actor} <- ActivityPub.get_or_fetch_actor_by_url(target_instance) do + Refresher.refresh_profile(target_actor) + end + end + @doc """ Publish an activity to all relays following this instance """ diff --git a/lib/mix/tasks/mobilizon/relay.ex b/lib/mix/tasks/mobilizon/relay.ex index d91b20065..4dc463a6a 100644 --- a/lib/mix/tasks/mobilizon/relay.ex +++ b/lib/mix/tasks/mobilizon/relay.ex @@ -65,4 +65,17 @@ defmodule Mix.Tasks.Mobilizon.Relay do IO.puts(:stderr, "Error while accept #{target} follow: #{inspect(e)}") end end + + def run(["refresh", target]) do + Common.start_mobilizon() + IO.puts("Refreshing #{target}, this can take a while.") + + case Relay.refresh(target) do + :ok -> + IO.puts("Refreshed #{target}") + + err -> + IO.puts(:stderr, "Error while refreshing #{target}: #{inspect(err)}") + end + end end