Add TwAPI representer for deletes.
authorRoger Braun <roger@rogerbraun.net>
Mon, 4 Sep 2017 18:03:28 +0000 (20:03 +0200)
committerRoger Braun <roger@rogerbraun.net>
Mon, 4 Sep 2017 18:03:28 +0000 (20:03 +0200)
lib/pleroma/web/twitter_api/representers/activity_representer.ex
test/web/twitter_api/representers/activity_representer_test.exs

index bc3de0e90d4b20c2478bcde1fc91d7c56430d46b..321917e838990d1a064ab03853623e1b8171ea8f 100644 (file)
@@ -96,6 +96,24 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
     }
   end
 
+  def to_map(%Activity{data: %{"type" => "Delete", "published" => created_at, "object" => deleted_object }} = activity, %{user: user} = opts) do
+    created_at = created_at |> Utils.date_to_asctime
+
+    %{
+      "id" => activity.data["object"],
+      "user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
+      "attentions" => [],
+      "statusnet_html" => "deleted notice {{tag",
+      "text" => "deleted notice {{tag" ,
+      "is_local" => activity.local,
+      "is_post_verb" => false,
+      "created_at" => created_at,
+      "in_reply_to_status_id" => nil,
+      "external_url" => activity.data["id"],
+      "activity_type" => "delete"
+    }
+  end
+
   def to_map(%Activity{data: %{"object" => %{"content" => content} = object}} = activity, %{user: user} = opts) do
     created_at = object["published"] |> Utils.date_to_asctime
     like_count = object["like_count"] || 0
index 4f090ee8eda575d63d58a0a533525e0d4ac008c7..906f8dd98ea3e9a0128ff56cb90954df4acca869 100644 (file)
@@ -148,4 +148,17 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
     assert map["is_post_verb"] == false
     assert map["activity_type"] == "undo"
   end
+
+  test "a delete activity" do
+    object = insert(:note)
+    user = User.get_by_ap_id(object.data["actor"])
+
+    {:ok, delete} = ActivityPub.delete(object)
+
+    map = ActivityRepresenter.to_map(delete, %{user: user})
+
+    assert map["is_post_verb"] == false
+    assert map["activity_type"] == "delete"
+    assert map["id"] == object.data["id"]
+  end
 end