ChatMessage: Correctly ingest emoji tags.
authorlain <lain@soykaf.club>
Thu, 23 Apr 2020 14:19:49 +0000 (16:19 +0200)
committerlain <lain@soykaf.club>
Thu, 23 Apr 2020 14:19:49 +0000 (16:19 +0200)
lib/pleroma/web/activity_pub/object_validators/chat_message_validator.ex
test/fixtures/create-chat-message.json
test/web/activity_pub/transmogrifier/chat_message_test.exs

index 8b5bb4fdcde2ed22ee060fd9b0448176fda74d99..f07045d9d19c1c75763a4a0fdabb02dc3c63bb8d 100644 (file)
@@ -9,6 +9,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatMessageValidator do
   alias Pleroma.Web.ActivityPub.ObjectValidators.Types
 
   import Ecto.Changeset
+  import Pleroma.Web.ActivityPub.Transmogrifier, only: [fix_emoji: 1]
 
   @primary_key false
   @derive Jason.Encoder
@@ -42,6 +43,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatMessageValidator do
 
   def fix(data) do
     data
+    |> fix_emoji()
     |> Map.put_new("actor", data["attributedTo"])
   end
 
index 6db5b9f5caae9389bfad33e605d428d15fa5063c..9c23a1c9b9a66a26428831527584465d9f44cce1 100644 (file)
@@ -9,6 +9,18 @@
     "to": [
       "http://2hu.gensokyo/users/marisa"
     ],
+    "tag": [
+      {
+        "icon": {
+          "type": "Image",
+          "url": "http://2hu.gensokyo/emoji/Firefox.gif"
+        },
+        "id": "http://2hu.gensokyo/emoji/Firefox.gif",
+        "name": ":firefox:",
+        "type": "Emoji",
+        "updated": "1970-01-01T00:00:00Z"
+      }
+    ],
     "type": "ChatMessage"
   },
   "published": "2018-02-12T14:08:20Z",
index 4d6f24609b98781205e137e59820e4276112033c..a63a31e6ed1815370dab796ae7e286176bbedf50 100644 (file)
@@ -75,6 +75,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.ChatMessageTest do
 
       assert object
       assert object.data["content"] == "You expected a cute girl? Too bad. alert(&#39;XSS&#39;)"
+      assert match?(%{"firefox" => _}, object.data["emoji"])
 
       refute Chat.get(author.id, recipient.ap_id)
       assert Chat.get(recipient.id, author.ap_id)