activitypub: add restrict_thread_visibility()
authorWilliam Pitcock <nenolod@dereferenced.org>
Mon, 25 Mar 2019 00:06:02 +0000 (00:06 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Wed, 15 May 2019 15:53:06 +0000 (15:53 +0000)
lib/pleroma/web/activity_pub/activity_pub.ex

index 233fee4fa7133b43adc87accabdc423baa608dc5..fec1bcd3ef21791dc94c9c32e2a39cd1b4c76923 100644 (file)
@@ -569,6 +569,20 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
 
   defp restrict_visibility(query, _visibility), do: query
 
+  defp restrict_thread_visibility(query, %{"user" => %User{ap_id: ap_id}}) do
+    query =
+      from(
+        a in query,
+        where: fragment("thread_visibility(?, (?)->>'id') = true", ^ap_id, a.data)
+      )
+
+    Ecto.Adapters.SQL.to_sql(:all, Repo, query)
+
+    query
+  end
+
+  defp restrict_thread_visibility(query, _), do: query
+
   def fetch_user_activities(user, reading_user, params \\ %{}) do
     params =
       params
@@ -848,6 +862,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     |> restrict_muted(opts)
     |> restrict_media(opts)
     |> restrict_visibility(opts)
+    |> restrict_thread_visibility(opts)
     |> restrict_replies(opts)
     |> restrict_reblogs(opts)
     |> restrict_pinned(opts)