From 7e9647b146a6b48ed32383f8379db5bf2a22277c Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sat, 8 Jul 2017 11:17:35 +0200 Subject: [PATCH] Fix undo activity. --- .../representers/activity_representer.ex | 20 +++++++++++++++++++ .../activity_representer_test.exs | 11 ++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex index a03b34ffb..10aab919a 100644 --- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex @@ -72,6 +72,26 @@ def to_map(%Activity{data: %{"type" => "Follow", "published" => created_at, "obj } end + # TODO: + # Make this more proper. Just a placeholder to not break the frontend. + def to_map(%Activity{data: %{"type" => "Undo", "published" => created_at, "object" => undid_activity }} = activity, %{user: user} = opts) do + created_at = created_at |> Utils.date_to_asctime + + text = "#{user.nickname} undid the action at #{undid_activity}" + %{ + "id" => activity.id, + "user" => UserView.render("show.json", %{user: user, for: opts[:for]}), + "attentions" => [], + "statusnet_html" => text, + "text" => text, + "is_local" => activity.local, + "is_post_verb" => false, + "created_at" => created_at, + "in_reply_to_status_id" => nil, + "external_url" => activity.data["id"] + } + 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 diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs index 777ad0bf5..e9f6a1915 100644 --- a/test/web/twitter_api/representers/activity_representer_test.exs +++ b/test/web/twitter_api/representers/activity_representer_test.exs @@ -132,4 +132,15 @@ test "an activity" do assert ActivityRepresenter.to_map(activity, %{user: user, for: follower, mentioned: [mentioned_user]}) == expected_status end + + test "an undo for a follow" do + follower = insert(:user) + followed = insert(:user) + + {:ok, follow} = ActivityPub.follow(follower, followed) + {:ok, unfollow} = ActivityPub.unfollow(follower, followed) + + map = ActivityRepresenter.to_map(unfollow, %{user: follower}) + assert map["is_post_verb"] == false + end end