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 @@ defp handle_client_event(%{"type" => "unsubscribe", "stream" => _topic} = params
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 @@ defp handle_client_event(
{[
{: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 @@ defp handle_client_event(
{[
{:text,
StreamerView.render("pleroma_respond.json", %{
type: "pleroma.authenticate",
type: "pleroma:authenticate",
result: "error",
error: :already_authenticated
})}
@ -242,7 +242,7 @@ defp handle_client_event(
{[
{:text,
StreamerView.render("pleroma_respond.json", %{
type: "pleroma.authenticate",
type: "pleroma:authenticate",
result: "error",
error: :unauthorized
})}

View File

@ -148,7 +148,7 @@ def render("conversation.json", %Participation{} = participation, topic) 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 @@ test "can subscribe" do
assert {:ok,
%{
"event" => "pleroma.respond",
"event" => "pleroma:respond",
"payload" => %{"type" => "subscribe", "result" => "success"}
}} = decode_json(raw_json)
@ -124,16 +124,20 @@ test "can subscribe to multiple streams" 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 @@ test "won't double subscribe" do
assert {:ok,
%{
"event" => "pleroma.respond",
"event" => "pleroma:respond",
"payload" => %{"type" => "subscribe", "result" => "success"}
}} = decode_json(raw_json)
@ -166,7 +170,7 @@ test "won't double subscribe" do
assert {:ok,
%{
"event" => "pleroma.respond",
"event" => "pleroma:respond",
"payload" => %{"type" => "subscribe", "result" => "ignored"}
}} = decode_json(raw_json)
@ -184,7 +188,7 @@ test "can unsubscribe" do
assert {:ok,
%{
"event" => "pleroma.respond",
"event" => "pleroma:respond",
"payload" => %{"type" => "subscribe", "result" => "success"}
}} = decode_json(raw_json)
@ -193,7 +197,7 @@ test "can unsubscribe" do
assert {:ok,
%{
"event" => "pleroma.respond",
"event" => "pleroma:respond",
"payload" => %{"type" => "unsubscribe", "result" => "success"}
}} = decode_json(raw_json)
@ -262,15 +266,15 @@ test "accepts valid token on client-sent event", %{token: token} 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 @@ test "accepts valid token on client-sent event", %{token: token} do
assert {:ok,
%{
"event" => "pleroma.respond",
"event" => "pleroma:respond",
"payload" => %{"type" => "subscribe", "result" => "success"}
}} = decode_json(raw_json)
end
@ -288,16 +292,16 @@ test "rejects invalid token on client-sent event" 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 @@ test "rejects new authenticate request if already logged-in", %{token: token} 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 @@ test "it sends chat messages to the 'user:pleroma_chat' stream", %{
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 @@ test "it sends chat messages to the 'user' stream", %{user: user, token: oauth_t
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}