query =
if has_named_binding?(query, :object), do: query, else: Activity.with_joined_object(query)
- # TODO: update after benchmarks
- query =
- case opts[:method] do
- :fun ->
- from(a in query,
- where:
- fragment(
- "recipients_contain_blocked_domains(?, ?) = false",
- a.recipients,
- ^domain_blocks
- )
- )
-
- :unnest ->
- from(a in query,
- where:
- fragment(
- "NOT ? && (SELECT ARRAY(SELECT split_part(UNNEST(?), '/', 3)))",
- ^domain_blocks,
- a.recipients
- )
- )
-
- _ ->
- query
- end
-
from(
[activity, object: o] in query,
where: fragment("not (? = ANY(?))", activity.actor, ^blocked_ap_ids),
where: fragment("not (? && ?)", activity.recipients, ^blocked_ap_ids),
+ where:
+ fragment(
+ "recipients_contain_blocked_domains(?, ?) = false",
+ activity.recipients,
+ ^domain_blocks
+ ),
where:
fragment(
"not (?->>'type' = 'Announce' and ?->'to' \\?| ?)",
end
end
+ defp exclude_invisible_actors(query, %{"invisible_actors" => true}), do: query
+
+ defp exclude_invisible_actors(query, _opts) do
+ invisible_ap_ids =
+ User.Query.build(%{invisible: true, select: [:ap_id]})
+ |> Repo.all()
+ |> Enum.map(fn %{ap_id: ap_id} -> ap_id end)
+
+ from([activity] in query, where: activity.actor not in ^invisible_ap_ids)
+ end
+
defp exclude_id(query, %{"exclude_id" => id}) when is_binary(id) do
from(activity in query, where: activity.id != ^id)
end
|> restrict_instance(opts)
|> Activity.restrict_deactivated_users()
|> exclude_poll_votes(opts)
+ |> exclude_invisible_actors(opts)
|> exclude_visibility(opts)
end