update ActivityPub#fetch_activities_query
authorMaksim Pechnikov <parallel588@gmail.com>
Tue, 4 Jun 2019 12:04:36 +0000 (15:04 +0300)
committerMaksim Pechnikov <parallel588@gmail.com>
Tue, 4 Jun 2019 12:04:36 +0000 (15:04 +0300)
lib/pleroma/web/activity_pub/activity_pub.ex

index 8c4d0c15d482ddacfcb585a4b86994ed359c312e..eefed58329eb6aaee66ee6916944031e486fec23 100644 (file)
@@ -558,14 +558,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
 
   defp restrict_visibility(query, %{visibility: visibility})
        when visibility in @valid_visibilities do
-    query =
-      from(
-        a in query,
-        where:
-          fragment("activity_visibility(?, ?, ?) = ?", a.actor, a.recipients, a.data, ^visibility)
-      )
-
-    query
+    from(
+      a in query,
+      where:
+        fragment("activity_visibility(?, ?, ?) = ?", a.actor, a.recipients, a.data, ^visibility)
+    )
   end
 
   defp restrict_visibility(_query, %{visibility: visibility})
@@ -575,17 +572,17 @@ 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)
-      )
+  defp restrict_thread_visibility(query, _, %{skip_thread_containment: true} = _),
+    do: query
 
-    query
+  defp restrict_thread_visibility(query, %{"user" => %User{ap_id: ap_id}}, _) do
+    from(
+      a in query,
+      where: fragment("thread_visibility(?, (?)->>'id') = true", ^ap_id, a.data)
+    )
   end
 
-  defp restrict_thread_visibility(query, _), do: query
+  defp restrict_thread_visibility(query, _, _), do: query
 
   def fetch_user_activities(user, reading_user, params \\ %{}) do
     params =
@@ -863,6 +860,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
 
   def fetch_activities_query(recipients, opts \\ %{}) do
     base_query = from(activity in Activity)
+    config = Enum.into(Config.get([:instance]), %{})
 
     base_query
     |> maybe_preload_objects(opts)
@@ -883,7 +881,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     |> restrict_muted(opts)
     |> restrict_media(opts)
     |> restrict_visibility(opts)
-    |> restrict_thread_visibility(opts)
+    |> restrict_thread_visibility(opts, config)
     |> restrict_replies(opts)
     |> restrict_reblogs(opts)
     |> restrict_pinned(opts)