ChatMessage: Support emoji.
This commit is contained in:
parent
b836d3d104
commit
7e53da250e
5 changed files with 29 additions and 20 deletions
|
@ -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 @@ defmodule Pleroma.Web.ActivityPub.Builder 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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
30
test/fixtures/create-chat-message.json
vendored
30
test/fixtures/create-chat-message.json
vendored
|
@ -1,19 +1,19 @@
|
|||
{
|
||||
"actor": "http://2hu.gensokyo/users/raymoo",
|
||||
"id": "http://2hu.gensokyo/objects/1",
|
||||
"object": {
|
||||
"attributedTo": "http://2hu.gensokyo/users/raymoo",
|
||||
"content": "You expected a cute girl? Too bad. <script>alert('XSS')</script>",
|
||||
"id": "http://2hu.gensokyo/objects/2",
|
||||
"published": "2020-02-12T14:08:20Z",
|
||||
"to": [
|
||||
"http://2hu.gensokyo/users/marisa"
|
||||
],
|
||||
"type": "ChatMessage"
|
||||
},
|
||||
"published": "2018-02-12T14:08:20Z",
|
||||
"actor": "http://2hu.gensokyo/users/raymoo",
|
||||
"id": "http://2hu.gensokyo/objects/1",
|
||||
"object": {
|
||||
"attributedTo": "http://2hu.gensokyo/users/raymoo",
|
||||
"content": "You expected a cute girl? Too bad. <script>alert('XSS')</script>",
|
||||
"id": "http://2hu.gensokyo/objects/2",
|
||||
"published": "2020-02-12T14:08:20Z",
|
||||
"to": [
|
||||
"http://2hu.gensokyo/users/marisa"
|
||||
"http://2hu.gensokyo/users/marisa"
|
||||
],
|
||||
"type": "Create"
|
||||
"type": "ChatMessage"
|
||||
},
|
||||
"published": "2018-02-12T14:08:20Z",
|
||||
"to": [
|
||||
"http://2hu.gensokyo/users/marisa"
|
||||
],
|
||||
"type": "Create"
|
||||
}
|
||||
|
|
|
@ -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", %{
|
||||
|
|
|
@ -33,7 +33,7 @@ defmodule Pleroma.Web.CommonAPITest 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 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
assert object.data["to"] == [recipient.ap_id]
|
||||
|
||||
assert object.data["content"] ==
|
||||
"a test message <script>alert('uuu')</script>"
|
||||
"a test message <script>alert('uuu')</script> :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)
|
||||
|
|
Loading…
Reference in a new issue