add `pinned` property to `StatusView`
authorEgor Kislitsyn <egor@kislitsyn.com>
Tue, 8 Jan 2019 08:27:02 +0000 (15:27 +0700)
committerEgor Kislitsyn <egor@kislitsyn.com>
Tue, 8 Jan 2019 08:27:02 +0000 (15:27 +0700)
lib/pleroma/web/mastodon_api/views/status_view.ex
test/web/mastodon_api/mastodon_api_controller_test.exs
test/web/mastodon_api/status_view_test.exs

index 8e8fa8121c475d79f809bc41af3a1aa5f78b3b48..db543ffe57a88e40479ee74ba981d694526a1c85 100644 (file)
@@ -76,6 +76,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
       reblogged: false,
       favourited: false,
       muted: false,
+      pinned: pinned?(activity, user),
       sensitive: false,
       spoiler_text: "",
       visibility: "public",
@@ -142,6 +143,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
       reblogged: present?(repeated),
       favourited: present?(favorited),
       muted: false,
+      pinned: pinned?(activity, user),
       sensitive: sensitive,
       spoiler_text: object["summary"] || "",
       visibility: get_visibility(object),
@@ -295,4 +297,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
   defp present?(nil), do: false
   defp present?(false), do: false
   defp present?(_), do: true
+
+  defp pinned?(%Activity{id: id}, %User{info: %{pinned_activities: pinned_activities}}),
+    do: id in pinned_activities
 end
index e7e42dd2428a44db35928ce64d2fbdfa7735386b..4a8c70b3ba9b2c98abef2d7a3688566f20150279 100644 (file)
@@ -1489,7 +1489,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
 
       id_str = Integer.to_string(activity.id)
 
-      assert [%{"id" => ^id_str}] = result
+      assert [%{"id" => ^id_str, "pinned" => true}] = result
     end
 
     test "pin status", %{conn: conn} do
@@ -1499,14 +1499,14 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
       {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
       id_str = Integer.to_string(activity.id)
 
-      assert %{"id" => ^id_str} =
+      assert %{"id" => ^id_str, "pinned" => true} =
                conn
                |> assign(:user, user)
                |> post("/api/v1/statuses/#{activity.id}/pin")
                |> Map.get(:resp_body)
                |> Jason.decode!()
 
-      assert [%{"id" => ^id_str}] =
+      assert [%{"id" => ^id_str, "pinned" => true}] =
                conn
                |> assign(:user, user)
                |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
@@ -1524,7 +1524,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
       id_str = Integer.to_string(activity.id)
       user = User.get_by_ap_id(user.ap_id)
 
-      assert %{"id" => ^id_str} =
+      assert %{"id" => ^id_str, "pinned" => false} =
                conn
                |> assign(:user, user)
                |> post("/api/v1/statuses/#{activity.id}/unpin")
@@ -1549,7 +1549,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
 
       id_str_one = Integer.to_string(activity_one.id)
 
-      assert %{"id" => ^id_str_one} =
+      assert %{"id" => ^id_str_one, "pinned" => true} =
                conn
                |> assign(:user, user)
                |> post("/api/v1/statuses/#{id_str_one}/pin")
index b953ccd76989bd96e1a99220a2020444ad755d4e..1076b500252455068be3f2036d7ae5ffccc7743c 100644 (file)
@@ -63,6 +63,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
       reblogged: false,
       favourited: false,
       muted: false,
+      pinned: false,
       sensitive: false,
       spoiler_text: note.data["object"]["summary"],
       visibility: "public",