Merge branch 'release/2.1.0' into 'stable'
[akkoma] / lib / mix / tasks / pleroma / relay.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Mix.Tasks.Pleroma.Relay do
6 use Mix.Task
7 import Mix.Pleroma
8 alias Pleroma.Web.ActivityPub.Relay
9
10 @shortdoc "Manages remote relays"
11 @moduledoc File.read!("docs/administration/CLI_tasks/relay.md")
12
13 def run(["follow", target]) do
14 start_pleroma()
15
16 with {:ok, _activity} <- Relay.follow(target) do
17 # put this task to sleep to allow the genserver to push out the messages
18 :timer.sleep(500)
19 else
20 {:error, e} -> shell_error("Error while following #{target}: #{inspect(e)}")
21 end
22 end
23
24 def run(["unfollow", target]) do
25 start_pleroma()
26
27 with {:ok, _activity} <- Relay.unfollow(target) do
28 # put this task to sleep to allow the genserver to push out the messages
29 :timer.sleep(500)
30 else
31 {:error, e} -> shell_error("Error while following #{target}: #{inspect(e)}")
32 end
33 end
34
35 def run(["list"]) do
36 start_pleroma()
37
38 with {:ok, list} <- Relay.list() do
39 Enum.each(list, &print_relay_url/1)
40 else
41 {:error, e} -> shell_error("Error while fetching relay subscription list: #{inspect(e)}")
42 end
43 end
44
45 defp print_relay_url(%{followed_back: false} = relay) do
46 shell_info("#{relay.actor} - no Accept received (relay didn't follow back)")
47 end
48
49 defp print_relay_url(relay), do: shell_info(relay.actor)
50 end