Handle Undo activites containing an Announce
authorFrancis Dinh <normandy@firemail.cc>
Wed, 9 May 2018 03:50:19 +0000 (23:50 -0400)
committerFrancis Dinh <normandy@firemail.cc>
Wed, 9 May 2018 03:50:19 +0000 (23:50 -0400)
lib/pleroma/web/activity_pub/transmogrifier.ex

index 2871a2544738086cffe934707c2359f9ec386aa5..8785ddaa9df1635e446d707e7621e6aea4a4b7b4 100644 (file)
@@ -220,9 +220,27 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
     end
   end
 
+  def handle_incoming(
+        %{
+          "type" => "Undo",
+          "object" => %{"type" => "Announce", "id" => object_id},
+          "actor" => actor,
+          "id" => id
+        } = data
+      ) do
+    with %User{} = actor <- User.get_or_fetch_by_ap_id(actor),
+         {:ok, object} <-
+           get_obj_helper(object_id) || ActivityPub.fetch_object_from_id(object_id),
+         {:ok, activity} <- ActivityPub.unannounce(object, false) do
+      {:ok, activity}
+    else
+      e -> :error
+    end
+  end
+
   # TODO
   # Accept
-  # Undo
+  # Undo for non-Announce
 
   def handle_incoming(_), do: :error