aboutsummaryrefslogtreecommitdiff
path: root/lib/mix/tasks/pleroma/relay.ex
blob: 4aea5273274f7ec405bc9cb928d8f9f1cb4b1d9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
defmodule Mix.Tasks.Pleroma.Relay do
  use Mix.Task
  alias Pleroma.Web.ActivityPub.Relay
  alias Mix.Tasks.Pleroma.Common

  @shortdoc "Manages remote relays"
  @moduledoc """
  Manages remote relays

  ## Follow a remote relay

  ``mix pleroma.relay unfollow <relay_url>``

  Example: ``mix pleroma.relay follow  https://example.org/relay``

  ## Unfollow a remote relay

  ``mix pleroma.relay unfollow <relay_url>``

  Example: ``mix pleroma.relay unfollow https://example.org/relay``
  """
  def run(["follow", target]) do
    Common.start_pleroma()

    with {:ok, activity} <- Relay.follow(target) do
      # put this task to sleep to allow the genserver to push out the messages
      :timer.sleep(500)
    else
      {:error, e} -> Mix.shell().error("Error while following #{target}: #{inspect(e)}")
    end
  end

  def run(["unfollow", target]) do
    Common.start_pleroma()

    with {:ok, activity} <- Relay.follow(target) do
      # put this task to sleep to allow the genserver to push out the messages
      :timer.sleep(500)
    else
      {:error, e} -> Mix.shell().error("Error while following #{target}: #{inspect(e)}")
    end
  end
end