+ defp restrict_thread_visibility(query, _, %{skip_thread_containment: true} = _),
+ do: query
+
+ defp restrict_thread_visibility(
+ query,
+ %{"user" => %User{info: %{skip_thread_containment: true}}},
+ _
+ ),
+ do: 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
+