[#534] Made Salmon.send_to_user calls be handled through Federator.enqueue.

This commit is contained in:
Ivan Tashkinov 2019-01-25 20:38:13 +03:00
parent 465adedb7c
commit 060d280e64
2 changed files with 12 additions and 8 deletions

View file

@ -6,7 +6,7 @@ defmodule Pleroma.Web.Federator do
use GenServer use GenServer
alias Pleroma.User alias Pleroma.User
alias Pleroma.Activity alias Pleroma.Activity
alias Pleroma.Web.{WebFinger, Websub} alias Pleroma.Web.{WebFinger, Websub, Salmon}
alias Pleroma.Web.Federator.RetryQueue alias Pleroma.Web.Federator.RetryQueue
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Relay alias Pleroma.Web.ActivityPub.Relay
@ -124,6 +124,10 @@ defmodule Pleroma.Web.Federator do
end end
end end
def handle(:publish_single_salmon, {user_or_url, feed, poster}) do
Salmon.send_to_user(user_or_url, feed, poster)
end
def handle(:publish_single_ap, params) do def handle(:publish_single_ap, params) do
case ActivityPub.publish_one(params) do case ActivityPub.publish_one(params) do
{:ok, _} -> {:ok, _} ->

View file

@ -164,10 +164,10 @@ defmodule Pleroma.Web.Salmon do
# push an activity to remote accounts # push an activity to remote accounts
# #
defp send_to_user(%{info: %{salmon: salmon}}, feed, poster), def send_to_user(%{info: %{salmon: salmon}}, feed, poster),
do: send_to_user(salmon, feed, poster) do: send_to_user(salmon, feed, poster)
defp send_to_user(url, feed, poster) when is_binary(url) do def send_to_user(url, feed, poster) when is_binary(url) do
with {:reachable, true} <- {:reachable, Instances.reachable?(url)}, with {:reachable, true} <- {:reachable, Instances.reachable?(url)},
{:ok, %{status: code}} when code in 200..299 <- {:ok, %{status: code}} when code in 200..299 <-
poster.( poster.(
@ -180,6 +180,7 @@ defmodule Pleroma.Web.Salmon do
) do ) do
Instances.set_reachable(url) Instances.set_reachable(url)
Logger.debug(fn -> "Pushed to #{url}, code #{code}" end) Logger.debug(fn -> "Pushed to #{url}, code #{code}" end)
:ok
else else
{:reachable, false} -> {:reachable, false} ->
Logger.debug(fn -> "Pushing Salmon to #{url} skipped as marked unreachable)" end) Logger.debug(fn -> "Pushing Salmon to #{url} skipped as marked unreachable)" end)
@ -188,10 +189,11 @@ defmodule Pleroma.Web.Salmon do
e -> e ->
Instances.set_unreachable(url) Instances.set_unreachable(url)
Logger.debug(fn -> "Pushing Salmon to #{url} failed, #{inspect(e)}" end) Logger.debug(fn -> "Pushing Salmon to #{url} failed, #{inspect(e)}" end)
:error
end end
end end
defp send_to_user(_, _, _), do: nil def send_to_user(_, _, _), do: :noop
@supported_activities [ @supported_activities [
"Create", "Create",
@ -229,10 +231,8 @@ defmodule Pleroma.Web.Salmon do
remote_users remote_users
|> Enum.filter(&(&1.info.salmon in reachable_salmon_urls)) |> Enum.filter(&(&1.info.salmon in reachable_salmon_urls))
|> Enum.each(fn remote_user -> |> Enum.each(fn remote_user ->
Task.start(fn -> Logger.debug(fn -> "Sending Salmon to #{remote_user.ap_id}" end)
Logger.debug(fn -> "Sending Salmon to #{remote_user.ap_id}" end) Pleroma.Web.Federator.enqueue(:publish_single_salmon, {remote_user, feed, poster})
send_to_user(remote_user, feed, poster)
end)
end) end)
end end
end end