mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-30 01:01:12 +00:00
ChatMessage: Support emoji.
This commit is contained in:
parent
b836d3d104
commit
7e53da250e
|
@ -5,6 +5,7 @@ defmodule Pleroma.Web.ActivityPub.Builder do
|
||||||
This module encodes our addressing policies and general shape of our objects.
|
This module encodes our addressing policies and general shape of our objects.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
alias Pleroma.Emoji
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.ActivityPub.Utils
|
alias Pleroma.Web.ActivityPub.Utils
|
||||||
|
@ -30,7 +31,8 @@ defmodule Pleroma.Web.ActivityPub.Builder do
|
||||||
"type" => "ChatMessage",
|
"type" => "ChatMessage",
|
||||||
"to" => [recipient],
|
"to" => [recipient],
|
||||||
"content" => content,
|
"content" => content,
|
||||||
"published" => DateTime.utc_now() |> DateTime.to_iso8601()
|
"published" => DateTime.utc_now() |> DateTime.to_iso8601(),
|
||||||
|
"emoji" => Emoji.Formatter.get_emoji_map(content)
|
||||||
}, []}
|
}, []}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatMessageValidator do
|
||||||
field(:content, :string)
|
field(:content, :string)
|
||||||
field(:actor, Types.ObjectID)
|
field(:actor, Types.ObjectID)
|
||||||
field(:published, Types.DateTime)
|
field(:published, Types.DateTime)
|
||||||
|
field(:emoji, :map, default: %{})
|
||||||
end
|
end
|
||||||
|
|
||||||
def cast_and_apply(data) do
|
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",
|
"actor": "http://2hu.gensokyo/users/raymoo",
|
||||||
"id": "http://2hu.gensokyo/objects/1",
|
"id": "http://2hu.gensokyo/objects/1",
|
||||||
"object": {
|
"object": {
|
||||||
"attributedTo": "http://2hu.gensokyo/users/raymoo",
|
"attributedTo": "http://2hu.gensokyo/users/raymoo",
|
||||||
"content": "You expected a cute girl? Too bad. <script>alert('XSS')</script>",
|
"content": "You expected a cute girl? Too bad. <script>alert('XSS')</script>",
|
||||||
"id": "http://2hu.gensokyo/objects/2",
|
"id": "http://2hu.gensokyo/objects/2",
|
||||||
"published": "2020-02-12T14:08:20Z",
|
"published": "2020-02-12T14:08:20Z",
|
||||||
"to": [
|
|
||||||
"http://2hu.gensokyo/users/marisa"
|
|
||||||
],
|
|
||||||
"type": "ChatMessage"
|
|
||||||
},
|
|
||||||
"published": "2018-02-12T14:08:20Z",
|
|
||||||
"to": [
|
"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)
|
user = insert(:user)
|
||||||
recipient = insert(:user, local: false)
|
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}
|
%{user: user, recipient: recipient, valid_chat_message: valid_chat_message}
|
||||||
end
|
end
|
||||||
|
|
||||||
test "validates for a basic object we build", %{valid_chat_message: valid_chat_message} do
|
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
|
end
|
||||||
|
|
||||||
test "does not validate if the message is longer than the remote_limit", %{
|
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(
|
CommonAPI.post_chat_message(
|
||||||
author,
|
author,
|
||||||
recipient,
|
recipient,
|
||||||
"a test message <script>alert('uuu')</script>"
|
"a test message <script>alert('uuu')</script> :firefox:"
|
||||||
)
|
)
|
||||||
|
|
||||||
assert activity.data["type"] == "Create"
|
assert activity.data["type"] == "Create"
|
||||||
|
@ -44,7 +44,11 @@ defmodule Pleroma.Web.CommonAPITest do
|
||||||
assert object.data["to"] == [recipient.ap_id]
|
assert object.data["to"] == [recipient.ap_id]
|
||||||
|
|
||||||
assert object.data["content"] ==
|
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(author.id, recipient.ap_id)
|
||||||
assert Chat.get(recipient.id, author.ap_id)
|
assert Chat.get(recipient.id, author.ap_id)
|
||||||
|
|
Loading…
Reference in a new issue