PleromaAPI: Add unreacting.
authorlain <lain@soykaf.club>
Wed, 2 Oct 2019 16:19:16 +0000 (18:19 +0200)
committerlain <lain@soykaf.club>
Wed, 2 Oct 2019 16:19:16 +0000 (18:19 +0200)
lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex
lib/pleroma/web/router.ex
test/web/pleroma_api/controllers/pleroma_api_controller_test.exs

index 884b3d877703af6464d7a7491abf339c61e39d36..8aee7d7c573cd22faae613b05ceb4bf8594874d2 100644 (file)
@@ -41,7 +41,19 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIController do
 
   def react_with_emoji(%{assigns: %{user: user}} = conn, %{"id" => activity_id, "emoji" => emoji}) do
     with {:ok, _activity, _object} <- CommonAPI.react_with_emoji(activity_id, user, emoji),
-         activity = Activity.get_by_id(activity_id) do
+         activity <- Activity.get_by_id(activity_id) do
+      conn
+      |> put_view(StatusView)
+      |> render("show.json", %{activity: activity, for: user, as: :activity})
+    end
+  end
+
+  def unreact_with_emoji(%{assigns: %{user: user}} = conn, %{
+        "id" => activity_id,
+        "emoji" => emoji
+      }) do
+    with {:ok, _activity, _object} <- CommonAPI.unreact_with_emoji(activity_id, user, emoji),
+         activity <- Activity.get_by_id(activity_id) do
       conn
       |> put_view(StatusView)
       |> render("show.json", %{activity: activity, for: user, as: :activity})
index ff3dc273ee817e121579ae6ff1120ddb62516d1d..87d373f554c547595f6f985103904961148ea317 100644 (file)
@@ -305,6 +305,7 @@ defmodule Pleroma.Web.Router do
       pipe_through(:oauth_write)
       patch("/conversations/:id", PleromaAPIController, :update_conversation)
       post("/statuses/:id/react_with_emoji", PleromaAPIController, :react_with_emoji)
+      post("/statuses/:id/unreact_with_emoji", PleromaAPIController, :unreact_with_emoji)
       post("/notifications/read", PleromaAPIController, :read_notification)
 
       patch("/accounts/update_avatar", AccountController, :update_avatar)
index 82d23ea5b985c717993114e69f3535a2466711ae..3a5dbdeead36b91d250983c2fc7a1f21c970a8df 100644 (file)
@@ -7,6 +7,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
 
   alias Pleroma.Conversation.Participation
   alias Pleroma.Notification
+  alias Pleroma.Object
   alias Pleroma.Repo
   alias Pleroma.Web.CommonAPI
 
@@ -41,6 +42,10 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
 
     assert %{"id" => id} = json_response(result, 200)
     assert to_string(activity.id) == id
+
+    object = Object.normalize(activity)
+
+    assert object.data["reaction_count"] == 0
   end
 
   test "GET /api/v1/pleroma/statuses/:id/emoji_reactions_by", %{conn: conn} do