logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

relay.ex (1678B)


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