+ defp filter_blocked_user(query, _), do: query
+
+ defp filter_blocked_domains(query, %User{domain_blocks: domain_blocks})
+ when length(domain_blocks) > 0 do
+ domains = Enum.join(domain_blocks, ",")
+
+ from(
+ q in query,
+ where: fragment("substring(ap_id from '.*://([^/]*)') NOT IN (?)", ^domains)
+ )
+ end
+
+ defp filter_blocked_domains(query, _), do: query
+
+ defp maybe_resolve(true, user, query) do
+ case {limit(), user} do
+ {:all, _} -> :noop
+ {:unauthenticated, %User{}} -> User.get_or_fetch(query)
+ {:unauthenticated, _} -> :noop
+ {false, _} -> User.get_or_fetch(query)
+ end
+ end
+
+ defp maybe_resolve(_, _, _), do: :noop
+
+ defp maybe_restrict_local(q, user) do
+ case {limit(), user} do
+ {:all, _} -> restrict_local(q)
+ {:unauthenticated, %User{}} -> q
+ {:unauthenticated, _} -> restrict_local(q)
+ {false, _} -> q
+ end
+ end
+
+ defp limit, do: Pleroma.Config.get([:instance, :limit_to_local_content], :unauthenticated)
+
+ defp restrict_local(q), do: where(q, [u], u.local == true)
+
+ defp local_domain, do: Pleroma.Config.get([Pleroma.Web.Endpoint, :url, :host])
+
+ defp boost_search_rank(query, %User{} = for_user) do