From 540dfb4617aaab400d0aeafa47d41544c00a2b83 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Mon, 4 Sep 2017 17:56:09 +0200 Subject: [PATCH] Add delete activity representer. --- .../web/ostatus/activity_representer.ex | 19 +++++++++++++++ .../web/ostatus/activity_representer_test.exs | 23 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex index d4b897e19..dda29d3cf 100644 --- a/lib/pleroma/web/ostatus/activity_representer.ex +++ b/lib/pleroma/web/ostatus/activity_representer.ex @@ -199,6 +199,25 @@ def to_simple_form(%{data: %{"type" => "Undo"}} = activity, user, with_author) d ] ++ 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, [ diff --git a/test/web/ostatus/activity_representer_test.exs b/test/web/ostatus/activity_representer_test.exs index 47eecb247..bcf569395 100644 --- a/test/web/ostatus/activity_representer_test.exs +++ b/test/web/ostatus/activity_representer_test.exs @@ -225,6 +225,29 @@ test "an unfollow activity" 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 = """ + http://activitystrea.ms/schema/1.0/activity + http://activitystrea.ms/schema/1.0/delete + #{activity.data["object"]} + An object was deleted + An object was deleted + #{activity.data["published"]} + #{activity.data["published"]} + """ + + assert clean(res) == clean(expected) + end + test "an unknown activity" do tuple = ActivityRepresenter.to_simple_form(%Activity{}, nil) assert is_nil(tuple)