X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fuser%2Fsearch.ex;h=a4f6abca24b358a0764977de3152f5a40a2868a4;hb=9134ef5ecb72f6fe2042f978be3deef41c9b4ce7;hp=408295e0ca75a49617903650a4d4e8f6975cb13e;hpb=d0078bc40406939cb584847c90b00aad006812e4;p=akkoma
diff --git a/lib/pleroma/user/search.ex b/lib/pleroma/user/search.ex
index 408295e0c..a4f6abca2 100644
--- a/lib/pleroma/user/search.ex
+++ b/lib/pleroma/user/search.ex
@@ -1,10 +1,12 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.User.Search do
+ alias Pleroma.EctoType.ActivityPub.ObjectValidators.Uri, as: UriType
alias Pleroma.Pagination
alias Pleroma.User
+
import Ecto.Query
@limit 20
@@ -21,15 +23,12 @@ defmodule Pleroma.User.Search do
# If this returns anything, it should bounce to the top
maybe_resolved = maybe_resolve(resolve, for_user, query_string)
- maybe_ap_id_match = User.get_cached_by_ap_id(query_string)
top_user_ids =
- case {maybe_resolved, maybe_ap_id_match} do
- {{:ok, %User{} = user}, %User{} = other_user} -> [user.id, other_user.id]
- {{:ok, %User{} = user}, _} -> [user.id]
- {_, %User{} = user} -> [user.id]
- _ -> []
- end
+ []
+ |> maybe_add_resolved(maybe_resolved)
+ |> maybe_add_ap_id_match(query_string)
+ |> maybe_add_uri_match(query_string)
results =
query_string
@@ -39,6 +38,30 @@ defmodule Pleroma.User.Search do
results
end
+ 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
+
defp format_query(query_string) do
# Strip the beginning @ off if there is a query
query_string = String.trim_leading(query_string, "@")
@@ -62,7 +85,6 @@ defmodule Pleroma.User.Search do
|> base_query(following)
|> filter_blocked_user(for_user)
|> filter_invisible_users()
- |> filter_discoverable_users()
|> filter_internal_users()
|> filter_blocked_domains(for_user)
|> fts_search(query_string)
@@ -140,10 +162,6 @@ defmodule Pleroma.User.Search do
from(q in query, where: q.invisible == false)
end
- defp filter_discoverable_users(query) do
- from(q in query, where: q.discoverable == true)
- end
-
defp filter_internal_users(query) do
from(q in query, where: q.actor_type != "Application")
end