Merge branch 'hotfix/delete-activities' into 'develop'
[akkoma] / lib / pleroma / gopher / server.ex
index e6361a82ca78a5161851e9449d85a9466d030341..6baacc5661ffbb4e3bec9dd4250cd469d1f53416 100644 (file)
@@ -1,48 +1,54 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
 defmodule Pleroma.Gopher.Server do
   use GenServer
   require Logger
 
-  def start_link() do
+  def start_link do
     config = Pleroma.Config.get(:gopher, [])
     ip = Keyword.get(config, :ip, {0, 0, 0, 0})
     port = Keyword.get(config, :port, 1234)
-    GenServer.start_link(__MODULE__, [ip, port], [])
-  end
 
-  def init([ip, port]) do
-    if Pleroma.Config.get([:gopher, :enabled], false) do
-      Logger.info("Starting gopher server on #{port}")
-
-      :ranch.start_listener(
-        :gopher,
-        100,
-        :ranch_tcp,
-        [port: port],
-        __MODULE__.ProtocolHandler,
-        []
-      )
-
-      {:ok, %{ip: ip, port: port}}
+    if Keyword.get(config, :enabled, false) do
+      GenServer.start_link(__MODULE__, [ip, port], [])
     else
       Logger.info("Gopher server disabled")
-      {:ok, nil}
+      :ignore
     end
   end
+
+  def init([ip, port]) do
+    Logger.info("Starting gopher server on #{port}")
+
+    :ranch.start_listener(
+      :gopher,
+      100,
+      :ranch_tcp,
+      [ip: ip, port: port],
+      __MODULE__.ProtocolHandler,
+      []
+    )
+
+    {:ok, %{ip: ip, port: port}}
+  end
 end
 
 defmodule Pleroma.Gopher.Server.ProtocolHandler do
-  alias Pleroma.Web.ActivityPub.ActivityPub
-  alias Pleroma.User
   alias Pleroma.Activity
-  alias Pleroma.Repo
   alias Pleroma.HTML
+  alias Pleroma.Repo
+  alias Pleroma.User
+  alias Pleroma.Web.ActivityPub.ActivityPub
+  alias Pleroma.Web.ActivityPub.Visibility
 
   def start_link(ref, socket, transport, opts) do
     pid = spawn_link(__MODULE__, :init, [ref, socket, transport, opts])
     {:ok, pid}
   end
 
-  def init(ref, socket, transport, _Opts = []) do
+  def init(ref, socket, transport, [] = _Opts) do
     :ok = :ranch.accept_ack(ref)
     loop(socket, transport)
   end
@@ -105,7 +111,7 @@ defmodule Pleroma.Gopher.Server.ProtocolHandler do
 
   def response("/notices/" <> id) do
     with %Activity{} = activity <- Repo.get(Activity, id),
-         true <- ActivityPub.is_public?(activity) do
+         true <- Visibility.is_public?(activity) do
       activities =
         ActivityPub.fetch_activities_for_context(activity.data["context"])
         |> render_activities