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
"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
field(:content, :string)
field(:actor, Types.ObjectID)
field(:published, Types.DateTime)
+ field(:emoji, :map, default: %{})
end
def cast_and_apply(data) do
{
- "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"
}
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", %{
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"
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)