diff options
author | tusooa <tusooa@kazv.moe> | 2022-10-09 02:05:27 +0000 |
---|---|---|
committer | tusooa <tusooa@kazv.moe> | 2022-10-09 02:05:27 +0000 |
commit | 59b8c920f62649b5b5902cf0e569749abe3d7991 (patch) | |
tree | 870cd2b7f437978fca89150db4d0703cc8898391 /lib/pleroma/web/streamer.ex | |
parent | b22843a98247cf683764759f3e447845f3fcedf8 (diff) | |
parent | 31fd41de0cbca28cd2461e96384460596e54e9e9 (diff) | |
download | pleroma-stable.tar.gz |
Release/2.4.4
See merge request pleroma/pleroma!3761
Diffstat (limited to 'lib/pleroma/web/streamer.ex')
-rw-r--r-- | lib/pleroma/web/streamer.ex | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/pleroma/web/streamer.ex b/lib/pleroma/web/streamer.ex index fc3bbb130..8bf70d99b 100644 --- a/lib/pleroma/web/streamer.ex +++ b/lib/pleroma/web/streamer.ex @@ -37,7 +37,7 @@ defmodule Pleroma.Web.Streamer do {:ok, topic :: String.t()} | {:error, :bad_topic} | {:error, :unauthorized} def get_topic_and_add_socket(stream, user, oauth_token, params \\ %{}) do with {:ok, topic} <- get_topic(stream, user, oauth_token, params) do - add_socket(topic, user) + add_socket(topic, oauth_token) end end @@ -120,10 +120,10 @@ defmodule Pleroma.Web.Streamer do end @doc "Registers the process for streaming. Use `get_topic/3` to get the full authorized topic." - def add_socket(topic, user) do + def add_socket(topic, oauth_token) do if should_env_send?() do - auth? = if user, do: true - Registry.register(@registry, topic, auth?) + oauth_token_id = if oauth_token, do: oauth_token.id, else: false + Registry.register(@registry, topic, oauth_token_id) end {:ok, topic} @@ -320,6 +320,22 @@ defmodule Pleroma.Web.Streamer do end end + def close_streams_by_oauth_token(oauth_token) do + if should_env_send?() do + Registry.select( + @registry, + [ + { + {:"$1", :"$2", :"$3"}, + [{:==, :"$3", oauth_token.id}], + [:"$2"] + } + ] + ) + |> Enum.each(fn pid -> send(pid, :close) end) + end + end + # In test environement, only return true if the registry is started. # In benchmark environment, returns false. # In any other environment, always returns true. |