CommonAPI: Support emoji reactions.
authorlain <lain@soykaf.club>
Tue, 27 Aug 2019 22:56:28 +0000 (17:56 -0500)
committerlain <lain@soykaf.club>
Tue, 27 Aug 2019 22:56:28 +0000 (17:56 -0500)
lib/pleroma/web/common_api/common_api.ex
test/web/common_api/common_api_test.exs

index 5faddc9f4e37f2e714104a193301b96a33a0dbef..3e1aa481897cacebef0270a75a0f97ca647e43eb 100644 (file)
@@ -123,6 +123,16 @@ defmodule Pleroma.Web.CommonAPI do
     end
   end
 
+  def react_with_emoji(id, user, emoji) do
+    with %Activity{} = activity <- Activity.get_by_id(id),
+         object <- Object.normalize(activity) do
+      ActivityPub.react_with_emoji(user, object, emoji)
+    else
+      _ ->
+        {:error, dgettext("errors", "Could not add reaction emoji")}
+    end
+  end
+
   def vote(user, object, choices) do
     with "Question" <- object.data["type"],
          {:author, false} <- {:author, object.data["actor"] == user.ap_id},
index f28a6609070c99063bf1ca3189a9f084dbb361a0..7cb1202fc8d906cfe3be005c33ec3e4ff94a0775 100644 (file)
@@ -222,6 +222,20 @@ defmodule Pleroma.Web.CommonAPITest do
   end
 
   describe "reactions" do
+    test "reacting to a status with an emoji" do
+      user = insert(:user)
+      other_user = insert(:user)
+
+      {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+
+      {:ok, reaction, _} = CommonAPI.react_with_emoji(activity.id, user, "👍")
+
+      assert reaction.data["actor"] == user.ap_id
+      assert reaction.data["content"] == "👍"
+
+      # TODO: test error case.
+    end
+
     test "repeating a status" do
       user = insert(:user)
       other_user = insert(:user)