Store private announcements in object.data["announcements"], filter them on display
authorThibaut Girka <thib@sitedethib.com>
Tue, 1 Oct 2019 19:40:35 +0000 (21:40 +0200)
committerThibaut Girka <thib@sitedethib.com>
Tue, 1 Oct 2019 20:39:25 +0000 (22:39 +0200)
lib/pleroma/web/activity_pub/utils.ex
lib/pleroma/web/mastodon_api/controllers/status_controller.ex
test/web/mastodon_api/controllers/status_controller_test.exs

index 2ba182f4e6412de4beb1cf731478b0c1d8f97ff9..0828591ee2a54f36610532209dc332db3a4c57c4 100644 (file)
@@ -494,7 +494,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
   @spec add_announce_to_object(Activity.t(), Object.t()) ::
           {:ok, Object.t()} | {:error, Ecto.Changeset.t()}
   def add_announce_to_object(
-        %Activity{data: %{"actor" => actor, "cc" => [Pleroma.Constants.as_public()]}},
+        %Activity{data: %{"actor" => actor}},
         object
       ) do
     announcements = take_announcements(object)
index 51456d453f2f6e070c99347198503cf557ca2bd2..79cced163dc4a98da36841968ee3ddedbc36197f 100644 (file)
@@ -242,7 +242,19 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do
   def reblogged_by(%{assigns: %{user: user}} = conn, %{"id" => id}) do
     with %Activity{} = activity <- Activity.get_by_id_with_object(id),
          {:visible, true} <- {:visible, Visibility.visible_for_user?(activity, user)},
-         %Object{data: %{"announcements" => announces}} <- Object.normalize(activity) do
+         %Object{data: %{"announcements" => announces, "id" => ap_id}} <-
+           Object.normalize(activity) do
+      announces =
+        "Announce"
+        |> Activity.Queries.by_type()
+        |> Ecto.Query.where([a], a.actor in ^announces)
+        # this is to use the index
+        |> Activity.Queries.by_object_id(ap_id)
+        |> Repo.all()
+        |> Enum.filter(&Visibility.visible_for_user?(&1, user))
+        |> Enum.map(& &1.actor)
+        |> Enum.uniq()
+
       users =
         User
         |> Ecto.Query.where([u], u.ap_id in ^announces)
index 727a233e74bdd0caf8fc823ffd010e0165247cde..b648ad6ff4547ecdf56bd47e0d7dab1eb5d34ead 100644 (file)
@@ -557,7 +557,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
         |> post("/api/v1/statuses/#{activity.id}/reblog", %{"visibility" => "private"})
 
       assert %{
-               "reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 0},
+               "reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 1},
                "reblogged" => true,
                "visibility" => "private"
              } = json_response(conn, 200)
@@ -1167,6 +1167,23 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
       assert Enum.empty?(response)
     end
 
+    test "does not return users who have reblogged the status privately", %{
+      conn: %{assigns: %{user: user}} = conn,
+      activity: activity
+    } do
+      other_user = insert(:user)
+
+      {:ok, _, _} = CommonAPI.repeat(activity.id, other_user, %{"visibility" => "private"})
+
+      response =
+        conn
+        |> assign(:user, user)
+        |> get("/api/v1/statuses/#{activity.id}/reblogged_by")
+        |> json_response(:ok)
+
+      assert Enum.empty?(response)
+    end
+
     test "does not fail on an unauthenticated request", %{conn: conn, activity: activity} do
       other_user = insert(:user)
       {:ok, _, _} = CommonAPI.repeat(activity.id, other_user)