fbec473c5d36578fb12f41cbe7e4778d8eaae9e2
[akkoma] / lib / mix / tasks / pleroma / relay.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 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 alias Mix.Tasks.Pleroma.Common
8 alias Pleroma.Web.ActivityPub.Relay
9
10 @shortdoc "Manages remote relays"
11 @moduledoc """
12 Manages remote relays
13
14 ## Follow a remote relay
15
16 ``mix pleroma.relay follow <relay_url>``
17
18 Example: ``mix pleroma.relay follow https://example.org/relay``
19
20 ## Unfollow a remote relay
21
22 ``mix pleroma.relay unfollow <relay_url>``
23
24 Example: ``mix pleroma.relay unfollow https://example.org/relay``
25 """
26 def run(["follow", target]) do
27 Common.start_pleroma()
28
29 with {:ok, _activity} <- Relay.follow(target) do
30 # put this task to sleep to allow the genserver to push out the messages
31 :timer.sleep(500)
32 else
33 {:error, e} -> Mix.shell().error("Error while following #{target}: #{inspect(e)}")
34 end
35 end
36
37 def run(["unfollow", target]) do
38 Common.start_pleroma()
39
40 with {:ok, _activity} <- Relay.unfollow(target) do
41 # put this task to sleep to allow the genserver to push out the messages
42 :timer.sleep(500)
43 else
44 {:error, e} -> Mix.shell().error("Error while following #{target}: #{inspect(e)}")
45 end
46 end
47 end