Fix undo activity.
authorRoger Braun <roger@rogerbraun.net>
Sat, 8 Jul 2017 09:17:35 +0000 (11:17 +0200)
committerRoger Braun <roger@rogerbraun.net>
Sat, 8 Jul 2017 09:17:35 +0000 (11:17 +0200)
lib/pleroma/web/twitter_api/representers/activity_representer.ex
test/web/twitter_api/representers/activity_representer_test.exs

index a03b34ffb9a29b70c37f226cc59dd93908e44ee9..10aab919a74ef1beb91fbb1802ab4944f42b22e7 100644 (file)
@@ -72,6 +72,26 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
     }
   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
index 777ad0bf5ceecec5597e8c4b4ac1cead3247d882..e9f6a1915c2e8f9fdf7c9981d3d79ba277726151 100644 (file)
@@ -132,4 +132,15 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest 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