Refactor common functions to common.ex
[akkoma] / lib / mix / tasks / pleroma / relay.ex
1 defmodule Mix.Tasks.Pleroma.Relay do
2 use Mix.Task
3 alias Pleroma.Web.ActivityPub.Relay
4 alias Mix.Tasks.Pleroma.Common
5
6 @shortdoc "Manages remote relays"
7 @moduledoc """
8 Manages remote relays
9
10 ## Follow a remote relay
11
12 ``mix pleroma.relay unfollow <relay_url>``
13
14 Example: ``mix pleroma.relay follow https://example.org/relay``
15
16 ## Unfollow a remote relay
17
18 ``mix pleroma.relay unfollow <relay_url>``
19
20 Example: ``mix pleroma.relay unfollow https://example.org/relay``
21 """
22 def run(["follow", target]) do
23 Common.start_pleroma
24 with {:ok, activity} <- Relay.follow(target) do
25 # put this task to sleep to allow the genserver to push out the messages
26 :timer.sleep(500)
27 else
28 {:error, e} -> Mix.shell().error("Error while following #{target}: #{inspect(e)}")
29 end
30 end
31
32 def run(["unfollow", target]) do
33 Common.start_pleroma
34
35 with {:ok, activity} <- Relay.follow(target) do
36 # put this task to sleep to allow the genserver to push out the messages
37 :timer.sleep(500)
38 else
39 {:error, e} -> Mix.shell().error("Error while following #{target}: #{inspect(e)}")
40 end
41 end
42 end