Add delete activity representer.
authorRoger Braun <roger@rogerbraun.net>
Mon, 4 Sep 2017 15:56:09 +0000 (17:56 +0200)
committerRoger Braun <roger@rogerbraun.net>
Mon, 4 Sep 2017 15:56:09 +0000 (17:56 +0200)
lib/pleroma/web/ostatus/activity_representer.ex
test/web/ostatus/activity_representer_test.exs

index d4b897e19129348a5020ac01a7587c15b8ca3980..dda29d3cf60fe664719ccba255b25b7504dcd0b7 100644 (file)
@@ -199,6 +199,25 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
     ] ++ mentions ++ author
   end
 
+  def to_simple_form(%{data: %{"type" => "Delete"}} = activity, user, with_author) do
+    h = fn(str) -> [to_charlist(str)] end
+
+    updated_at = activity.data["published"]
+    inserted_at = activity.data["published"]
+
+    author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
+
+    [
+      {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/activity']},
+      {:"activity:verb", ['http://activitystrea.ms/schema/1.0/delete']},
+      {:id, h.(activity.data["object"])},
+      {:title, ['An object was deleted']},
+      {:content, [type: 'html'], ['An object was deleted']},
+      {:published, h.(inserted_at)},
+      {:updated, h.(updated_at)}
+    ]  ++ author
+  end
+
   def wrap_with_entry(simple_form) do
     [{
       :entry, [
index 47eecb247dadbcf599245eae7182f58fc1eb9118..bcf569395fce53109d188ef7ee774f46b03f45fb 100644 (file)
@@ -225,6 +225,29 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
     assert clean(res) == clean(expected)
   end
 
+  test "a delete" do
+    user = insert(:user)
+    activity = %Activity{data: %{ "id" => "ap_id", "type" => "Delete", "actor" => user.ap_id, "object" => "some_id", "published" => "2017-06-18T12:00:18+00:00" }}
+
+    tuple = ActivityRepresenter.to_simple_form(activity, nil)
+
+    refute is_nil(tuple)
+
+    res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary
+
+    expected = """
+    <activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type>
+    <activity:verb>http://activitystrea.ms/schema/1.0/delete</activity:verb>
+    <id>#{activity.data["object"]}</id>
+    <title>An object was deleted</title>
+    <content type="html">An object was deleted</content>
+    <published>#{activity.data["published"]}</published>
+    <updated>#{activity.data["published"]}</updated>
+    """
+
+    assert clean(res) == clean(expected)
+  end
+
   test "an unknown activity" do
     tuple = ActivityRepresenter.to_simple_form(%Activity{}, nil)
     assert is_nil(tuple)