Merge remote-tracking branch 'origin/develop' into sixohsix/pleroma-post_expiration
[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 import Mix.Pleroma
8 alias Pleroma.User
9 alias Pleroma.Web.ActivityPub.Relay
10
11 @shortdoc "Manages remote relays"
12 @moduledoc """
13 Manages remote relays
14
15 ## Follow a remote relay
16
17 ``mix pleroma.relay follow <relay_url>``
18
19 Example: ``mix pleroma.relay follow https://example.org/relay``
20
21 ## Unfollow a remote relay
22
23 ``mix pleroma.relay unfollow <relay_url>``
24
25 Example: ``mix pleroma.relay unfollow https://example.org/relay``
26
27 ## List relay subscriptions
28
29 ``mix pleroma.relay list``
30 """
31 def run(["follow", target]) do
32 start_pleroma()
33
34 with {:ok, _activity} <- Relay.follow(target) do
35 # put this task to sleep to allow the genserver to push out the messages
36 :timer.sleep(500)
37 else
38 {:error, e} -> shell_error("Error while following #{target}: #{inspect(e)}")
39 end
40 end
41
42 def run(["unfollow", target]) do
43 start_pleroma()
44
45 with {:ok, _activity} <- Relay.unfollow(target) do
46 # put this task to sleep to allow the genserver to push out the messages
47 :timer.sleep(500)
48 else
49 {:error, e} -> shell_error("Error while following #{target}: #{inspect(e)}")
50 end
51 end
52
53 def run(["list"]) do
54 start_pleroma()
55
56 with %User{following: following} = _user <- Relay.get_actor() do
57 following
58 |> Enum.map(fn entry -> URI.parse(entry).host end)
59 |> Enum.uniq()
60 |> Enum.each(&shell_info(&1))
61 else
62 e -> shell_error("Error while fetching relay subscription list: #{inspect(e)}")
63 end
64 end
65 end