From 29e69b3a4c82fa64a6632cb6bf31ee4d7f1d1436 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 23 Sep 2020 16:59:22 +0300 Subject: tmp --- lib/pleroma/web/fed_sockets/adapter.ex | 25 ++++++++++++++++--------- lib/pleroma/web/fed_sockets/adapter/gun.ex | 4 ++-- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/pleroma/web/fed_sockets/adapter.ex b/lib/pleroma/web/fed_sockets/adapter.ex index f35c964c6..05e74fa78 100644 --- a/lib/pleroma/web/fed_sockets/adapter.ex +++ b/lib/pleroma/web/fed_sockets/adapter.ex @@ -28,14 +28,17 @@ defmodule Pleroma.Web.FedSockets.Adapter do {:reply, term(), waiting_fetches()} | {:noreply, waiting_fetches()} def process_message(message, origin, waiting_fetches) when is_binary(message) do case Jason.decode(message) do - {:ok, message} -> process_message(message, origin, waiting_fetches) + {:ok, message} -> do_process_message(message, origin, waiting_fetches) # 1003 indicates that an endpoint is terminating the connection # because it has received a type of data it cannot accept. {:error, decode_error} -> {:reply, {:close, 1003, Exception.message(decode_error)}} end end - def process_message(%{"action" => "publish", "data" => data}, origin, waiting_fetches) do + def process_message(message, origin, waiting_fetches), + do: do_process_message(message, origin, waiting_fetches) + + defp do_process_message(%{"action" => "publish", "data" => data}, origin, waiting_fetches) do if Containment.contain_origin(origin, data) do Federator.incoming_ap_doc(data) end @@ -43,7 +46,11 @@ defmodule Pleroma.Web.FedSockets.Adapter do {:noreply, waiting_fetches} end - def process_message(%{"action" => "fetch", "uuid" => uuid, "data" => ap_id}, _, waiting_fetches) do + defp do_process_message( + %{"action" => "fetch", "uuid" => uuid, "data" => ap_id}, + _, + waiting_fetches + ) do data = %{ "action" => "fetch_reply", "status" => "processed", @@ -54,11 +61,11 @@ defmodule Pleroma.Web.FedSockets.Adapter do {:reply, {:text, Jason.encode!(data)}, waiting_fetches} end - def process_message( - %{"action" => "fetch_reply", "uuid" => uuid, "data" => data}, - _, - waiting_fetches - ) do + defp do_process_message( + %{"action" => "fetch_reply", "uuid" => uuid, "data" => data}, + _, + waiting_fetches + ) do with {pid, waiting_fetches} when is_pid(pid) <- Map.pop(waiting_fetches, uuid) do send(pid, {:fetch_reply, uuid, data}) {:noreply, waiting_fetches} @@ -68,7 +75,7 @@ defmodule Pleroma.Web.FedSockets.Adapter do end end - def process_message(_, _, waiting_fetches) do + defp do_process_message(_, _, waiting_fetches) do {:reply, {:close, 1003, "Unknown message type."}, waiting_fetches} end diff --git a/lib/pleroma/web/fed_sockets/adapter/gun.ex b/lib/pleroma/web/fed_sockets/adapter/gun.ex index 9984b666e..2fd0a5aa4 100644 --- a/lib/pleroma/web/fed_sockets/adapter/gun.ex +++ b/lib/pleroma/web/fed_sockets/adapter/gun.ex @@ -130,8 +130,8 @@ defmodule Pleroma.Web.FedSockets.Adapter.Gun do end @impl true - def handle_info({:gun_down, _pid, _prot, :closed, _}, state) do - {:stop, :normal, state} + def handle_info({:gun_down, conn_pid, _, reason, _}, %{conn_pid: conn_pid} = state) do + {:stop, reason, state} end @impl true -- cgit v1.2.3