mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-23 08:36:29 +00:00
excluded invisible users from search results
This commit is contained in:
parent
4b7c11e3f9
commit
62bc0657e7
2 changed files with 13 additions and 0 deletions
|
@ -45,6 +45,7 @@ defmodule Pleroma.User.Search do
|
||||||
for_user
|
for_user
|
||||||
|> base_query(following)
|
|> base_query(following)
|
||||||
|> filter_blocked_user(for_user)
|
|> filter_blocked_user(for_user)
|
||||||
|
|> filter_invisible_users()
|
||||||
|> filter_blocked_domains(for_user)
|
|> filter_blocked_domains(for_user)
|
||||||
|> fts_search(query_string)
|
|> fts_search(query_string)
|
||||||
|> trigram_rank(query_string)
|
|> trigram_rank(query_string)
|
||||||
|
@ -98,6 +99,10 @@ defmodule Pleroma.User.Search do
|
||||||
defp base_query(_user, false), do: User
|
defp base_query(_user, false), do: User
|
||||||
defp base_query(user, true), do: User.get_followers_query(user)
|
defp base_query(user, true), do: User.get_followers_query(user)
|
||||||
|
|
||||||
|
defp filter_invisible_users(query) do
|
||||||
|
from(q in query, where: q.invisible == false)
|
||||||
|
end
|
||||||
|
|
||||||
defp filter_blocked_user(query, %User{blocks: blocks})
|
defp filter_blocked_user(query, %User{blocks: blocks})
|
||||||
when length(blocks) > 0 do
|
when length(blocks) > 0 do
|
||||||
from(q in query, where: not (q.ap_id in ^blocks))
|
from(q in query, where: not (q.ap_id in ^blocks))
|
||||||
|
|
|
@ -15,6 +15,14 @@ defmodule Pleroma.UserSearchTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "User.search" do
|
describe "User.search" do
|
||||||
|
test "excluded invisible users from results" do
|
||||||
|
user = insert(:user, %{nickname: "john t1000"})
|
||||||
|
insert(:user, %{invisible: true, nickname: "john t800"})
|
||||||
|
|
||||||
|
[found_user] = User.search("john")
|
||||||
|
assert found_user.id == user.id
|
||||||
|
end
|
||||||
|
|
||||||
test "accepts limit parameter" do
|
test "accepts limit parameter" do
|
||||||
Enum.each(0..4, &insert(:user, %{nickname: "john#{&1}"}))
|
Enum.each(0..4, &insert(:user, %{nickname: "john#{&1}"}))
|
||||||
assert length(User.search("john", limit: 3)) == 3
|
assert length(User.search("john", limit: 3)) == 3
|
||||||
|
|
Loading…
Reference in a new issue