+ defp maybe_add_resolved(list, {:ok, %User{} = user}) do
+ [user.id | list]
+ end
+
+ defp maybe_add_resolved(list, _), do: list
+
+ defp maybe_add_ap_id_match(list, query) do
+ if user = User.get_cached_by_ap_id(query) do
+ [user.id | list]
+ else
+ list
+ end
+ end
+
+ defp maybe_add_uri_match(list, query) do
+ with {:ok, query} <- UriType.cast(query),
+ q = from(u in User, where: u.uri == ^query, select: u.id),
+ users = Pleroma.Repo.all(q) do
+ users ++ list
+ else
+ _ -> list
+ end
+ end
+
+ def sanitise_domain(domain) do
+ domain
+ |> String.replace(~r/[!-\,|@|?|<|>|[-`|{-~|\/|:|\s]+/, "")
+ end
+
+ defp format_query(query_string) do
+ # Strip the beginning @ off if there is a query
+ query_string = String.trim_leading(query_string, "@")
+
+ with [name, domain] <- String.split(query_string, "@") do
+ encoded_domain =
+ domain
+ |> sanitise_domain()
+ |> String.to_charlist()
+ |> :idna.encode()
+ |> to_string()
+
+ name <> "@" <> encoded_domain
+ else
+ _ -> query_string
+ end
+ end
+
+ defp search_query(query_string, for_user, following, top_user_ids) do