ChatChannel: Ignore messages that are too long.
This commit is contained in:
parent
7722e5a67a
commit
aa97fe8f17
|
@ -225,6 +225,7 @@
|
|||
notify_email: "noreply@example.com",
|
||||
description: "A Pleroma instance, an alternative fediverse server",
|
||||
limit: 5_000,
|
||||
chat_limit: 5_000,
|
||||
remote_limit: 100_000,
|
||||
upload_limit: 16_000_000,
|
||||
avatar_upload_limit: 2_000_000,
|
||||
|
|
|
@ -147,8 +147,6 @@ defp oauth_cleanup_child(true),
|
|||
|
||||
defp oauth_cleanup_child(_), do: []
|
||||
|
||||
defp chat_child(:test, _), do: []
|
||||
|
||||
defp chat_child(_env, true) do
|
||||
[Pleroma.Web.ChatChannel.ChatChannelState]
|
||||
end
|
||||
|
|
|
@ -20,7 +20,7 @@ def handle_info(:after_join, socket) do
|
|||
def handle_in("new_msg", %{"text" => text}, %{assigns: %{user_name: user_name}} = socket) do
|
||||
text = String.trim(text)
|
||||
|
||||
if String.length(text) > 0 do
|
||||
if String.length(text) in 1..Pleroma.Config.get([:instance, :chat_limit]) do
|
||||
author = User.get_cached_by_nickname(user_name)
|
||||
author = Pleroma.Web.MastodonAPI.AccountView.render("show.json", user: author)
|
||||
message = ChatChannelState.add_message(%{text: text, author: author})
|
||||
|
|
|
@ -23,6 +23,7 @@ defmodule Pleroma.Web.ChannelCase do
|
|||
quote do
|
||||
# Import conveniences for testing with channels
|
||||
use Phoenix.ChannelTest
|
||||
use Pleroma.Tests.Helpers
|
||||
|
||||
# The default endpoint for testing
|
||||
@endpoint Pleroma.Web.Endpoint
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
defmodule Pleroma.Web.ChatChannelTest do
|
||||
use Pleroma.Web.ChannelCase
|
||||
alias Pleroma.Web.ChatChannel
|
||||
alias Pleroma.Web.UserSocket
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
setup do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, _, socket} =
|
||||
socket(UserSocket, "", %{user_name: user.nickname})
|
||||
|> subscribe_and_join(ChatChannel, "chat:public")
|
||||
|
||||
{:ok, socket: socket}
|
||||
end
|
||||
|
||||
test "it broadcasts a message", %{socket: socket} do
|
||||
push(socket, "new_msg", %{"text" => "why is tenshi eating a corndog so cute?"})
|
||||
assert_broadcast("new_msg", %{text: "why is tenshi eating a corndog so cute?"})
|
||||
end
|
||||
|
||||
describe "message lengths" do
|
||||
clear_config([:instance, :chat_limit])
|
||||
|
||||
test "it ignores messages of length zero", %{socket: socket} do
|
||||
push(socket, "new_msg", %{"text" => ""})
|
||||
refute_broadcast("new_msg", %{text: ""})
|
||||
end
|
||||
|
||||
test "it ignores messages above a certain length", %{socket: socket} do
|
||||
Pleroma.Config.put([:instance, :chat_limit], 2)
|
||||
push(socket, "new_msg", %{"text" => "123"})
|
||||
refute_broadcast("new_msg", %{text: "123"})
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue