Web.MastodonAPI.MastodonSocket: Add unauthentified websocket endpoints
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Sat, 24 Nov 2018 05:13:36 +0000 (06:13 +0100)
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Sat, 24 Nov 2018 05:13:36 +0000 (06:13 +0100)
reported by soka on CRTNet

lib/pleroma/web/mastodon_api/mastodon_socket.ex

index 0f3d5ff7c8832bf74cb213b2a7d331da2aa21767..46ec5ecd2c1b0bce538101327e1bcd307e6a82af 100644 (file)
@@ -45,6 +45,24 @@ defmodule Pleroma.Web.MastodonAPI.MastodonSocket do
     end
   end
 
+  def connect(%{"stream" => stream} = params, socket)
+      when stream in ["public", "public:local", "hashtag"] do
+    topic =
+      case stream do
+        "hashtag" -> "hashtag:#{params["tag"]}"
+        _ -> stream
+      end
+
+    with socket =
+           socket
+           |> assign(:topic, topic) do
+      Pleroma.Web.Streamer.add_socket(topic, socket)
+      {:ok, socket}
+    else
+      _e -> :error
+    end
+  end
+
   def id(_), do: nil
 
   def handle(:text, message, _state) do