ChatMessage: Support emoji.

This commit is contained in:
lain 2020-04-20 14:08:54 +02:00
parent b836d3d104
commit 7e53da250e
5 changed files with 29 additions and 20 deletions

View File

@ -5,6 +5,7 @@ defmodule Pleroma.Web.ActivityPub.Builder do
This module encodes our addressing policies and general shape of our objects.
"""
alias Pleroma.Emoji
alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Web.ActivityPub.Utils
@ -30,7 +31,8 @@ def chat_message(actor, recipient, content) do
"type" => "ChatMessage",
"to" => [recipient],
"content" => content,
"published" => DateTime.utc_now() |> DateTime.to_iso8601()
"published" => DateTime.utc_now() |> DateTime.to_iso8601(),
"emoji" => Emoji.Formatter.get_emoji_map(content)
}, []}
end

View File

@ -20,6 +20,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatMessageValidator do
field(:content, :string)
field(:actor, Types.ObjectID)
field(:published, Types.DateTime)
field(:emoji, :map, default: %{})
end
def cast_and_apply(data) do

View File

@ -15,13 +15,15 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidatorTest do
user = insert(:user)
recipient = insert(:user, local: false)
{:ok, valid_chat_message, _} = Builder.chat_message(user, recipient.ap_id, "hey")
{:ok, valid_chat_message, _} = Builder.chat_message(user, recipient.ap_id, "hey :firefox:")
%{user: user, recipient: recipient, valid_chat_message: valid_chat_message}
end
test "validates for a basic object we build", %{valid_chat_message: valid_chat_message} do
assert {:ok, _object, _meta} = ObjectValidator.validate(valid_chat_message, [])
assert {:ok, object, _meta} = ObjectValidator.validate(valid_chat_message, [])
assert object == valid_chat_message
end
test "does not validate if the message is longer than the remote_limit", %{

View File

@ -33,7 +33,7 @@ test "it posts a chat message" do
CommonAPI.post_chat_message(
author,
recipient,
"a test message <script>alert('uuu')</script>"
"a test message <script>alert('uuu')</script> :firefox:"
)
assert activity.data["type"] == "Create"
@ -44,7 +44,11 @@ test "it posts a chat message" do
assert object.data["to"] == [recipient.ap_id]
assert object.data["content"] ==
"a test message &lt;script&gt;alert(&#39;uuu&#39;)&lt;/script&gt;"
"a test message &lt;script&gt;alert(&#39;uuu&#39;)&lt;/script&gt; :firefox:"
assert object.data["emoji"] == %{
"firefox" => "http://localhost:4001/emoji/Firefox.gif"
}
assert Chat.get(author.id, recipient.ap_id)
assert Chat.get(recipient.id, author.ap_id)