[#1892] Excluded bot actors (applications, services) from search results.
authorIvan Tashkinov <ivantashkinov@gmail.com>
Tue, 30 Jun 2020 18:26:39 +0000 (21:26 +0300)
committerIvan Tashkinov <ivantashkinov@gmail.com>
Tue, 30 Jun 2020 18:26:39 +0000 (21:26 +0300)
lib/pleroma/user/search.ex
test/user_search_test.exs

index cec59c372b835f76c2b54f0e68e814e6282c7366..0293c6ae74070a0d2901a561baa9a358fe7869ce 100644 (file)
@@ -52,6 +52,7 @@ defmodule Pleroma.User.Search do
     |> base_query(following)
     |> filter_blocked_user(for_user)
     |> filter_invisible_users()
+    |> filter_bots()
     |> filter_blocked_domains(for_user)
     |> fts_search(query_string)
     |> trigram_rank(query_string)
@@ -109,6 +110,10 @@ defmodule Pleroma.User.Search do
     from(q in query, where: q.invisible == false)
   end
 
+  defp filter_bots(query) do
+    from(q in query, where: q.actor_type not in ["Application", "Service"])
+  end
+
   defp filter_blocked_user(query, %User{} = blocker) do
     query
     |> join(:left, [u], b in Pleroma.UserRelationship,
index 17c63322a979eade277c42cf62a0782af95b8f0c..9a74b9764b20666857d8f0ad0785d50f16b5cf27 100644 (file)
@@ -17,7 +17,7 @@ defmodule Pleroma.UserSearchTest do
   describe "User.search" do
     setup do: clear_config([:instance, :limit_to_local_content])
 
-    test "excluded invisible users from results" do
+    test "excludes invisible users from results" do
       user = insert(:user, %{nickname: "john t1000"})
       insert(:user, %{invisible: true, nickname: "john t800"})
 
@@ -25,6 +25,13 @@ defmodule Pleroma.UserSearchTest do
       assert found_user.id == user.id
     end
 
+    test "excludes bots from results" do
+      insert(:user, actor_type: "Service", nickname: "bot1")
+      insert(:user, actor_type: "Application", nickname: "bot2")
+
+      assert [] = User.search("bot")
+    end
+
     test "accepts limit parameter" do
       Enum.each(0..4, &insert(:user, %{nickname: "john#{&1}"}))
       assert length(User.search("john", limit: 3)) == 3