ChatMessageView: Support emoji.
authorlain <lain@soykaf.club>
Mon, 20 Apr 2020 12:38:53 +0000 (14:38 +0200)
committerlain <lain@soykaf.club>
Mon, 20 Apr 2020 12:38:53 +0000 (14:38 +0200)
lib/pleroma/web/pleroma_api/views/chat_message_view.ex
test/web/pleroma_api/views/chat_message_view_test.exs

index fdbb9ff1bd0177cfd969dfe277659be56b4dd61a..b40ab92a023cdb605e27aca516283f9c92fdef86 100644 (file)
@@ -6,6 +6,8 @@ defmodule Pleroma.Web.PleromaAPI.ChatMessageView do
   use Pleroma.Web, :view
 
   alias Pleroma.Chat
+  alias Pleroma.Web.CommonAPI.Utils
+  alias Pleroma.Web.MastodonAPI.StatusView
 
   def render(
         "show.json",
@@ -18,7 +20,9 @@ defmodule Pleroma.Web.PleromaAPI.ChatMessageView do
       id: id |> to_string(),
       content: chat_message["content"],
       chat_id: chat_id |> to_string(),
-      actor: chat_message["actor"]
+      actor: chat_message["actor"],
+      created_at: Utils.to_masto_date(chat_message["published"]),
+      emojis: StatusView.build_emojis(chat_message["emoji"])
     }
   end
 
index ad8febee6478cba5e1006cba0c8e8dd2bd76caf4..115335f10aa9f0eeb2387a4613a5a2d39192cb9e 100644 (file)
@@ -15,7 +15,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatMessageViewTest do
   test "it displays a chat message" do
     user = insert(:user)
     recipient = insert(:user)
-    {:ok, activity} = CommonAPI.post_chat_message(user, recipient, "kippis")
+    {:ok, activity} = CommonAPI.post_chat_message(user, recipient, "kippis :firefox:")
 
     chat = Chat.get(user.id, recipient.ap_id)
 
@@ -24,9 +24,11 @@ defmodule Pleroma.Web.PleromaAPI.ChatMessageViewTest do
     chat_message = ChatMessageView.render("show.json", object: object, for: user, chat: chat)
 
     assert chat_message[:id] == object.id |> to_string()
-    assert chat_message[:content] == "kippis"
+    assert chat_message[:content] == "kippis :firefox:"
     assert chat_message[:actor] == user.ap_id
     assert chat_message[:chat_id]
+    assert chat_message[:created_at]
+    assert match?([%{shortcode: "firefox"}], chat_message[:emojis])
 
     {:ok, activity} = CommonAPI.post_chat_message(recipient, user, "gkgkgk")