fix not being able to pin polls
authorrinpatch <rinpatch@sdf.org>
Sun, 2 Feb 2020 11:55:06 +0000 (14:55 +0300)
committerrinpatch <rinpatch@sdf.org>
Sun, 2 Feb 2020 11:55:06 +0000 (14:55 +0300)
lib/pleroma/web/common_api/common_api.ex
test/web/common_api/common_api_test.exs

index c05a6c544f3f3eb2ff7578ceda844224c8289c9e..2a348dcf6a9459593faeb7aa2beb6009ba8d8ca5 100644 (file)
@@ -315,8 +315,9 @@ defmodule Pleroma.Web.CommonAPI do
     with %Activity{
            actor: ^user_ap_id,
            data: %{"type" => "Create"},
-           object: %Object{data: %{"type" => "Note"}}
+           object: %Object{data: %{"type" => object_type}}
          } = activity <- get_by_id_or_ap_id(id_or_ap_id),
+         true <- object_type in ["Note", "Article", "Question"],
          true <- Visibility.is_public?(activity),
          {:ok, _user} <- User.add_pinnned_activity(user, activity) do
       {:ok, activity}
index 8fa0c6faa952d7c7a6bb6fbe38c659df8c4d9190..214cbdd7cee31423970fb1ba904dc88cf65bcb8a 100644 (file)
@@ -324,6 +324,21 @@ defmodule Pleroma.Web.CommonAPITest do
       assert %User{pinned_activities: [^id]} = user
     end
 
+    test "pin poll", %{user: user} do
+      {:ok, activity} =
+        CommonAPI.post(user, %{
+          "status" => "How is fediverse today?",
+          "poll" => %{"options" => ["Absolutely outstanding", "Not good"], "expires_in" => 20}
+        })
+
+      assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
+
+      id = activity.id
+      user = refresh_record(user)
+
+      assert %User{pinned_activities: [^id]} = user
+    end
+
     test "unlisted statuses can be pinned", %{user: user} do
       {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!", "visibility" => "unlisted"})
       assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)