use GenServer
alias Pleroma.User
alias Pleroma.Activity
- alias Pleroma.Web.{WebFinger, Websub}
+ alias Pleroma.Web.{WebFinger, Websub, Salmon}
alias Pleroma.Web.Federator.RetryQueue
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Relay
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
case ActivityPub.publish_one(params) do
{:ok, _} ->
# 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)
- 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)},
{:ok, %{status: code}} when code in 200..299 <-
poster.(
) do
Instances.set_reachable(url)
Logger.debug(fn -> "Pushed to #{url}, code #{code}" end)
+ :ok
else
{:reachable, false} ->
Logger.debug(fn -> "Pushing Salmon to #{url} skipped as marked unreachable)" end)
e ->
Instances.set_unreachable(url)
Logger.debug(fn -> "Pushing Salmon to #{url} failed, #{inspect(e)}" end)
+ :error
end
end
- defp send_to_user(_, _, _), do: nil
+ def send_to_user(_, _, _), do: :noop
@supported_activities [
"Create",
remote_users
|> Enum.filter(&(&1.info.salmon in reachable_salmon_urls))
|> Enum.each(fn remote_user ->
- Task.start(fn ->
- Logger.debug(fn -> "Sending Salmon to #{remote_user.ap_id}" end)
- send_to_user(remote_user, feed, poster)
- end)
+ Logger.debug(fn -> "Sending Salmon to #{remote_user.ap_id}" end)
+ Pleroma.Web.Federator.enqueue(:publish_single_salmon, {remote_user, feed, poster})
end)
end
end