Transmogrifier: Handle misskey likes with reactions like EmojiReactions.
authorlain <lain@soykaf.club>
Fri, 4 Oct 2019 15:01:04 +0000 (17:01 +0200)
committerlain <lain@soykaf.club>
Fri, 4 Oct 2019 15:01:04 +0000 (17:01 +0200)
lib/pleroma/web/activity_pub/transmogrifier.ex
test/fixtures/misskey-like.json [new file with mode: 0644]
test/web/activity_pub/transmogrifier_test.exs

index ea209b5ea1b73e81d23de17e4726fd422a420c30..54c18bc0e920e0647563d7e051c6137065afa1c7 100644 (file)
@@ -560,6 +560,33 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
     end
   end
 
+  @misskey_reactions %{
+    "like" => "👍",
+    "love" => "❤️",
+    "laugh" => "😆",
+    "hmm" => "🤔",
+    "surprise" => "😮",
+    "congrats" => "🎉",
+    "angry" => "💢",
+    "confused" => "😥",
+    "rip" => "😇",
+    "pudding" => "🍮"
+  }
+
+  @doc "Rewrite misskey likes into EmojiReactions"
+  def handle_incoming(
+        %{
+          "type" => "Like",
+          "_misskey_reaction" => reaction
+        } = data,
+        options
+      ) do
+    data
+    |> Map.put("type", "EmojiReaction")
+    |> Map.put("content", @misskey_reactions[reaction])
+    |> handle_incoming(options)
+  end
+
   def handle_incoming(
         %{"type" => "Like", "object" => object_id, "actor" => _actor, "id" => id} = data,
         _options
diff --git a/test/fixtures/misskey-like.json b/test/fixtures/misskey-like.json
new file mode 100644 (file)
index 0000000..84d56f4
--- /dev/null
@@ -0,0 +1,14 @@
+{
+  "@context" : [
+    "https://www.w3.org/ns/activitystreams",
+    "https://w3id.org/security/v1",
+    {"Hashtag" : "as:Hashtag"}
+  ],
+  "_misskey_reaction" : "pudding",
+  "actor": "http://mastodon.example.org/users/admin",
+  "cc" : ["https://testing.pleroma.lol/users/lain"],
+  "id" : "https://misskey.xyz/75149198-2f45-46e4-930a-8b0538297075",
+  "nickname" : "lain",
+  "object" : "https://testing.pleroma.lol/objects/c331bbf7-2eb9-4801-a709-2a6103492a5a",
+  "type" : "Like"
+}
index a9544caf2a98065ff08f360e503fc43b4a70e319..530a762fa9acbed34ea147d54ae619f8204882ab 100644 (file)
@@ -341,6 +341,24 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
       assert data["object"] == activity.data["object"]
     end
 
+    test "it works for incoming misskey likes, turning them into EmojiReactions" do
+      user = insert(:user)
+      {:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
+
+      data =
+        File.read!("test/fixtures/misskey-like.json")
+        |> Poison.decode!()
+        |> Map.put("object", activity.data["object"])
+
+      {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+
+      assert data["actor"] == data["actor"]
+      assert data["type"] == "EmojiReaction"
+      assert data["id"] == data["id"]
+      assert data["object"] == activity.data["object"]
+      assert data["content"] == "🍮"
+    end
+
     test "it works for incoming emoji reactions" do
       user = insert(:user)
       {:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})