Use pleroma: instead of pleroma. for ws events

This commit is contained in:
tusooa 2023-04-01 01:29:11 -04:00
parent 7d005e8c93
commit a348c2e4dd
No known key found for this signature in database
GPG Key ID: 42AEC43D48433C51
4 changed files with 42 additions and 28 deletions

View File

@ -215,7 +215,7 @@ defmodule Pleroma.Web.MastodonAPI.WebsocketHandler do
end
defp handle_client_event(
%{"type" => "pleroma.authenticate", "token" => access_token} = _params,
%{"type" => "pleroma:authenticate", "token" => access_token} = _params,
state
) do
with {:auth, nil, nil} <- {:auth, state.user, state.oauth_token},
@ -223,7 +223,7 @@ defmodule Pleroma.Web.MastodonAPI.WebsocketHandler do
{[
{:text,
StreamerView.render("pleroma_respond.json", %{
type: "pleroma.authenticate",
type: "pleroma:authenticate",
result: "success"
})}
], %{state | user: user, oauth_token: oauth_token}}
@ -232,7 +232,7 @@ defmodule Pleroma.Web.MastodonAPI.WebsocketHandler do
{[
{:text,
StreamerView.render("pleroma_respond.json", %{
type: "pleroma.authenticate",
type: "pleroma:authenticate",
result: "error",
error: :already_authenticated
})}
@ -242,7 +242,7 @@ defmodule Pleroma.Web.MastodonAPI.WebsocketHandler do
{[
{:text,
StreamerView.render("pleroma_respond.json", %{
type: "pleroma.authenticate",
type: "pleroma:authenticate",
result: "error",
error: :unauthorized
})}

View File

@ -148,7 +148,7 @@ defmodule Pleroma.Web.StreamerView do
def render("pleroma_respond.json", %{type: type, result: result} = params) do
%{
event: "pleroma.respond",
event: "pleroma:respond",
payload:
%{
result: result,

View File

@ -95,7 +95,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
assert {:ok,
%{
"event" => "pleroma.respond",
"event" => "pleroma:respond",
"payload" => %{"type" => "subscribe", "result" => "success"}
}} = decode_json(raw_json)
@ -124,16 +124,20 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
assert {:ok,
%{
"event" => "pleroma.respond",
"event" => "pleroma:respond",
"payload" => %{"type" => "subscribe", "result" => "success"}
}} = decode_json(raw_json)
WebsocketClient.send_text(pid, %{type: "subscribe", stream: "hashtag", tag: "mew"} |> Jason.encode!())
WebsocketClient.send_text(
pid,
%{type: "subscribe", stream: "hashtag", tag: "mew"} |> Jason.encode!()
)
assert_receive {:text, raw_json}, 1_000
assert {:ok,
%{
"event" => "pleroma.respond",
"event" => "pleroma:respond",
"payload" => %{"type" => "subscribe", "result" => "success"}
}} = decode_json(raw_json)
@ -157,7 +161,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
assert {:ok,
%{
"event" => "pleroma.respond",
"event" => "pleroma:respond",
"payload" => %{"type" => "subscribe", "result" => "success"}
}} = decode_json(raw_json)
@ -166,7 +170,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
assert {:ok,
%{
"event" => "pleroma.respond",
"event" => "pleroma:respond",
"payload" => %{"type" => "subscribe", "result" => "ignored"}
}} = decode_json(raw_json)
@ -184,7 +188,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
assert {:ok,
%{
"event" => "pleroma.respond",
"event" => "pleroma:respond",
"payload" => %{"type" => "subscribe", "result" => "success"}
}} = decode_json(raw_json)
@ -193,7 +197,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
assert {:ok,
%{
"event" => "pleroma.respond",
"event" => "pleroma:respond",
"payload" => %{"type" => "unsubscribe", "result" => "success"}
}} = decode_json(raw_json)
@ -262,15 +266,15 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
WebsocketClient.send_text(
pid,
%{type: "pleroma.authenticate", token: token.token} |> Jason.encode!()
%{type: "pleroma:authenticate", token: token.token} |> Jason.encode!()
)
assert_receive {:text, raw_json}, 1_000
assert {:ok,
%{
"event" => "pleroma.respond",
"payload" => %{"type" => "pleroma.authenticate", "result" => "success"}
"event" => "pleroma:respond",
"payload" => %{"type" => "pleroma:authenticate", "result" => "success"}
}} = decode_json(raw_json)
WebsocketClient.send_text(pid, %{type: "subscribe", stream: "user"} |> Jason.encode!())
@ -278,7 +282,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
assert {:ok,
%{
"event" => "pleroma.respond",
"event" => "pleroma:respond",
"payload" => %{"type" => "subscribe", "result" => "success"}
}} = decode_json(raw_json)
end
@ -288,16 +292,16 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
WebsocketClient.send_text(
pid,
%{type: "pleroma.authenticate", token: "Something else"} |> Jason.encode!()
%{type: "pleroma:authenticate", token: "Something else"} |> Jason.encode!()
)
assert_receive {:text, raw_json}, 1_000
assert {:ok,
%{
"event" => "pleroma.respond",
"event" => "pleroma:respond",
"payload" => %{
"type" => "pleroma.authenticate",
"type" => "pleroma:authenticate",
"result" => "error",
"error" => "unauthorized"
}
@ -309,29 +313,29 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
WebsocketClient.send_text(
pid,
%{type: "pleroma.authenticate", token: token.token} |> Jason.encode!()
%{type: "pleroma:authenticate", token: token.token} |> Jason.encode!()
)
assert_receive {:text, raw_json}, 1_000
assert {:ok,
%{
"event" => "pleroma.respond",
"payload" => %{"type" => "pleroma.authenticate", "result" => "success"}
"event" => "pleroma:respond",
"payload" => %{"type" => "pleroma:authenticate", "result" => "success"}
}} = decode_json(raw_json)
WebsocketClient.send_text(
pid,
%{type: "pleroma.authenticate", token: "Something else"} |> Jason.encode!()
%{type: "pleroma:authenticate", token: "Something else"} |> Jason.encode!()
)
assert_receive {:text, raw_json}, 1_000
assert {:ok,
%{
"event" => "pleroma.respond",
"event" => "pleroma:respond",
"payload" => %{
"type" => "pleroma.authenticate",
"type" => "pleroma:authenticate",
"result" => "error",
"error" => "already_authenticated"
}

View File

@ -355,7 +355,12 @@ defmodule Pleroma.Web.StreamerTest do
Streamer.get_topic_and_add_socket("user:pleroma_chat", user, oauth_token)
Streamer.stream("user:pleroma_chat", {user, cm_ref})
text = StreamerView.render("chat_update.json", %{chat_message_reference: cm_ref}, "user:pleroma_chat:#{user.id}")
text =
StreamerView.render(
"chat_update.json",
%{chat_message_reference: cm_ref},
"user:pleroma_chat:#{user.id}"
)
assert text =~ "hey cirno"
assert_receive {:text, ^text}
@ -373,7 +378,12 @@ defmodule Pleroma.Web.StreamerTest do
Streamer.get_topic_and_add_socket("user", user, oauth_token)
Streamer.stream("user", {user, cm_ref})
text = StreamerView.render("chat_update.json", %{chat_message_reference: cm_ref}, "user:#{user.id}")
text =
StreamerView.render(
"chat_update.json",
%{chat_message_reference: cm_ref},
"user:#{user.id}"
)
assert text =~ "hey cirno"
assert_receive {:text, ^text}