2019-07-30 16:40:59 +02:00
|
|
|
# Portions of this file are derived from Pleroma:
|
|
|
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/mix/tasks/pleroma/relay.ex
|
|
|
|
|
|
|
|
defmodule Mix.Tasks.Mobilizon.Relay do
|
|
|
|
@moduledoc """
|
|
|
|
Manages remote relays
|
|
|
|
|
|
|
|
## Follow a remote relay
|
|
|
|
|
|
|
|
``mix mobilizon.relay follow <relay_url>``
|
|
|
|
|
|
|
|
Example: ``mix mobilizon.relay follow https://example.org/relay``
|
|
|
|
|
|
|
|
## Unfollow a remote relay
|
|
|
|
|
|
|
|
``mix mobilizon.relay unfollow <relay_url>``
|
|
|
|
|
|
|
|
Example: ``mix mobilizon.relay unfollow https://example.org/relay``
|
|
|
|
"""
|
2019-09-22 16:26:23 +02:00
|
|
|
|
|
|
|
use Mix.Task
|
|
|
|
|
|
|
|
alias Mix.Tasks.Mobilizon.Common
|
2020-01-26 21:11:16 +01:00
|
|
|
|
2020-01-22 02:14:42 +01:00
|
|
|
alias Mobilizon.Federation.ActivityPub.Relay
|
2019-09-22 16:26:23 +02:00
|
|
|
|
|
|
|
@shortdoc "Manages remote relays"
|
2019-07-30 16:40:59 +02:00
|
|
|
def run(["follow", target]) do
|
|
|
|
Common.start_mobilizon()
|
|
|
|
|
|
|
|
case Relay.follow(target) do
|
2019-12-03 11:29:51 +01:00
|
|
|
{:ok, _activity, _follow} ->
|
2019-07-30 16:40:59 +02:00
|
|
|
# put this task to sleep to allow the genserver to push out the messages
|
|
|
|
:timer.sleep(500)
|
|
|
|
|
|
|
|
{:error, e} ->
|
|
|
|
IO.puts(:stderr, "Error while following #{target}: #{inspect(e)}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def run(["unfollow", target]) do
|
|
|
|
Common.start_mobilizon()
|
|
|
|
|
|
|
|
case Relay.unfollow(target) do
|
2019-12-03 11:29:51 +01:00
|
|
|
{:ok, _activity, _follow} ->
|
2019-07-30 16:40:59 +02:00
|
|
|
# put this task to sleep to allow the genserver to push out the messages
|
|
|
|
:timer.sleep(500)
|
|
|
|
|
|
|
|
{:error, e} ->
|
|
|
|
IO.puts(:stderr, "Error while unfollowing #{target}: #{inspect(e)}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def run(["accept", target]) do
|
|
|
|
Common.start_mobilizon()
|
|
|
|
|
|
|
|
case Relay.accept(target) do
|
|
|
|
{:ok, _activity} ->
|
|
|
|
# put this task to sleep to allow the genserver to push out the messages
|
|
|
|
:timer.sleep(500)
|
|
|
|
|
|
|
|
{:error, e} ->
|
|
|
|
IO.puts(:stderr, "Error while accept #{target} follow: #{inspect(e)}")
|
|
|
|
end
|
|
|
|
end
|
2020-10-21 11:02:28 +02:00
|
|
|
|
|
|
|
def run(["refresh", target]) do
|
|
|
|
Common.start_mobilizon()
|
|
|
|
IO.puts("Refreshing #{target}, this can take a while.")
|
|
|
|
|
|
|
|
case Relay.refresh(target) do
|
|
|
|
:ok ->
|
|
|
|
IO.puts("Refreshed #{target}")
|
|
|
|
|
|
|
|
err ->
|
|
|
|
IO.puts(:stderr, "Error while refreshing #{target}: #{inspect(err)}")
|
|
|
|
end
|
|
|
|
end
|
2019-07-30 16:40:59 +02:00
|
|
|
end
|