removes duplicates from relay subscription list

This commit is contained in:
Maksim Pechnikov 2019-08-19 13:31:56 +03:00
parent 3315a2a1c3
commit e652cef76b
2 changed files with 28 additions and 7 deletions

View File

@ -53,13 +53,11 @@ defmodule Mix.Tasks.Pleroma.Relay do
def run(["list"]) do def run(["list"]) do
start_pleroma() start_pleroma()
with %User{} = user <- Relay.get_actor() do with %User{following: following} = _user <- Relay.get_actor() do
user.following following
|> Enum.each(fn entry -> |> Enum.map(fn entry -> URI.parse(entry).host end)
URI.parse(entry) |> Enum.uniq()
|> Map.get(:host) |> Enum.each(&shell_info(&1))
|> shell_info()
end)
else else
e -> shell_error("Error while fetching relay subscription list: #{inspect(e)}") e -> shell_error("Error while fetching relay subscription list: #{inspect(e)}")
end end

View File

@ -69,4 +69,27 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
assert undo_activity.data["object"] == cancelled_activity.data assert undo_activity.data["object"] == cancelled_activity.data
end end
end end
describe "mix pleroma.relay list" do
test "Prints relay subscription list" do
:ok = Mix.Tasks.Pleroma.Relay.run(["list"])
refute_receive {:mix_shell, :info, _}
Pleroma.Web.ActivityPub.Relay.get_actor()
|> Ecto.Changeset.change(
following: [
"http://test-app.com/user/test1",
"http://test-app.com/user/test1",
"http://test-app-42.com/user/test1"
]
)
|> Pleroma.User.update_and_set_cache()
:ok = Mix.Tasks.Pleroma.Relay.run(["list"])
assert_receive {:mix_shell, :info, ["test-app.com"]}
assert_receive {:mix_shell, :info, ["test-app-42.com"]}
end
end
end end