Chat: Add views, don't return them in timeline queries.

This commit is contained in:
lain 2020-04-15 18:23:16 +02:00
commit 6ace22b56a
9 changed files with 207 additions and 38 deletions

View file

@ -51,6 +51,9 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
{:ok, activity} = CommonAPI.post(third_user, %{"status" => "repeated post"})
{:ok, _, _} = CommonAPI.repeat(activity.id, following)
# This one should not show up in the TL
{:ok, _activity} = CommonAPI.post_chat_message(third_user, user, ":gun:")
ret_conn = get(conn, uri)
assert Enum.empty?(json_response(ret_conn, :ok))

View file

@ -23,14 +23,13 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|> json_response(200)
assert result["content"] == "Hallo!!"
assert result["chat_id"] == chat.id
end
end
describe "GET /api/v1/pleroma/chats/:id/messages" do
# TODO
# - Test that statuses don't show
# - Test the case where it's not the user's chat
# - Test the returned data
test "it returns the messages for a given chat", %{conn: conn} do
user = insert(:user)
other_user = insert(:user)
@ -49,6 +48,11 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|> get("/api/v1/pleroma/chats/#{chat.id}/messages")
|> json_response(200)
result
|> Enum.each(fn message ->
assert message["chat_id"] == chat.id
end)
assert length(result) == 3
end
end

View file

@ -0,0 +1,42 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.ChatMessageViewTest do
use Pleroma.DataCase
alias Pleroma.Chat
alias Pleroma.Object
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.PleromaAPI.ChatMessageView
import Pleroma.Factory
test "it displays a chat message" do
user = insert(:user)
recipient = insert(:user)
{:ok, activity} = CommonAPI.post_chat_message(user, recipient, "kippis")
chat = Chat.get(user.id, recipient.ap_id)
object = Object.normalize(activity)
chat_message = ChatMessageView.render("show.json", object: object, for: user, chat: chat)
assert chat_message[:id] == object.id
assert chat_message[:content] == "kippis"
assert chat_message[:actor] == user.ap_id
assert chat_message[:chat_id]
{:ok, activity} = CommonAPI.post_chat_message(recipient, user, "gkgkgk")
object = Object.normalize(activity)
chat_message_two = ChatMessageView.render("show.json", object: object, for: user, chat: chat)
assert chat_message_two[:id] == object.id
assert chat_message_two[:content] == "gkgkgk"
assert chat_message_two[:actor] == recipient.ap_id
assert chat_message_two[:chat_id] == chat_message[:chat_id]
end
end