Embed announce activity data instead of linking to it
authorFrancis Dinh <normandy@firemail.cc>
Mon, 23 Apr 2018 01:28:51 +0000 (21:28 -0400)
committerFrancis Dinh <normandy@firemail.cc>
Mon, 23 Apr 2018 01:28:51 +0000 (21:28 -0400)
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/activity_pub/utils.ex
test/web/activity_pub/activity_pub_test.exs

index ace230804fb6a0e16071be2a36a34d1851a69752..63d893039ba0dd3867a93779799c22a0b0ba9298 100644 (file)
@@ -140,9 +140,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     end
   end
 
-  def unannounce(%User{} = actor, %Object{} = object, local \\ true) do
+  def unannounce(
+        %User{} = actor,
+        %Object{} = object,
+        local \\ true,
+        activity_id \\ nil
+      ) do
     with %Activity{} = activity <- get_existing_announce(actor.ap_id, object),
-         unannounce_data <- make_unannounce_data(actor, activity),
+         unannounce_data <- make_unannounce_data(actor, activity, activity_id),
          {:ok, unannounce_activity} <- insert(unannounce_data, local),
          :ok <- maybe_federate(activity),
          {:ok, _activity} <- Repo.delete(activity),
index 9e2fa1fb22967875b0e8050b11e8f15854122462..10cc044febe74c34c300a18a70774c58f4727df1 100644 (file)
@@ -283,16 +283,19 @@ defmodule Pleroma.Web.ActivityPub.Utils do
   """
   def make_unannounce_data(
         %User{ap_id: ap_id} = user,
-        %Activity{data: %{"id" => id, "context" => context}} = activity
+        %Activity{data: %{"context" => context}} = activity,
+        activity_id
       ) do
-    %{
+    data = %{
       "type" => "Undo",
       "actor" => ap_id,
-      "object" => id,
+      "object" => activity.data,
       "to" => [user.follower_address, activity.data["actor"]],
       "cc" => ["https://www.w3.org/ns/activitystreams#Public"],
       "context" => context
     }
+
+    if activity_id, do: Map.put(data, "id", activity_id), else: data
   end
 
   def add_announce_to_object(%Activity{data: %{"actor" => actor}}, object) do
index e3258ed4edecd5a9f2379598393333dde10641ce..208cc42d2a094edfa749769ccb055b954d296b57 100644 (file)
@@ -292,9 +292,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
       assert unannounce_activity.data["to"] == [
                User.ap_followers(user),
                announce_activity.data["actor"]
-      ]
+             ]
       assert unannounce_activity.data["type"] == "Undo"
-      assert unannounce_activity.data["object"] == announce_activity.data["id"]
+      assert unannounce_activity.data["object"] == announce_activity.data
       assert unannounce_activity.data["actor"] == user.ap_id
       assert unannounce_activity.data["context"] == announce_activity.data["context"]