CommonAPI: Obey local limit for chat messages.

This commit is contained in:
lain 2020-04-20 12:08:47 +02:00
commit 5b6818b3e5
4 changed files with 28 additions and 4 deletions

View file

@ -23,6 +23,8 @@ defmodule Pleroma.Web.CommonAPITest do
setup do: clear_config([:instance, :max_pinned_statuses])
describe "posting chat messages" do
setup do: clear_config([:instance, :chat_limit])
test "it posts a chat message" do
author = insert(:user)
recipient = insert(:user)
@ -47,6 +49,22 @@ defmodule Pleroma.Web.CommonAPITest do
assert Chat.get(author.id, recipient.ap_id)
assert Chat.get(recipient.id, author.ap_id)
end
test "it reject messages over the local limit" do
Pleroma.Config.put([:instance, :chat_limit], 2)
author = insert(:user)
recipient = insert(:user)
{:error, message} =
CommonAPI.post_chat_message(
author,
recipient,
"123"
)
assert message == :content_too_long
end
end
test "when replying to a conversation / participation, it will set the correct context id even if no explicit reply_to is given" do

View file

@ -23,7 +23,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatMessageViewTest do
chat_message = ChatMessageView.render("show.json", object: object, for: user, chat: chat)
assert chat_message[:id] == object.id
assert chat_message[:id] == object.id |> to_string()
assert chat_message[:content] == "kippis"
assert chat_message[:actor] == user.ap_id
assert chat_message[:chat_id]
@ -34,7 +34,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatMessageViewTest do
chat_message_two = ChatMessageView.render("show.json", object: object, for: user, chat: chat)
assert chat_message_two[:id] == object.id
assert chat_message_two[:id] == object.id |> to_string()
assert chat_message_two[:content] == "gkgkgk"
assert chat_message_two[:actor] == recipient.ap_id
assert chat_message_two[:chat_id] == chat_message[:chat_id]

View file

@ -2,7 +2,7 @@
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.ChatMessageViewTest do
defmodule Pleroma.Web.PleromaAPI.ChatViewTest do
use Pleroma.DataCase
alias Pleroma.Chat