Merge branch 'fix-searching-following' into 'develop'
authorrinpatch <rinpatch@sdf.org>
Wed, 2 Sep 2020 06:55:58 +0000 (06:55 +0000)
committerrinpatch <rinpatch@sdf.org>
Tue, 8 Sep 2020 09:53:02 +0000 (12:53 +0300)
search: fix 'following' query parameter

See merge request pleroma/pleroma!2943

CHANGELOG.md
lib/pleroma/user/search.ex
test/user_search_test.exs

index 0850deed78558f5443ea79ee84cfd4f71a4ef2b2..07bc6d77c4446866ab11bd5846e2b3d35a8178a8 100644 (file)
@@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file.
 
 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 
+## unreleased-patch - ???
+
+### Fixed
+- Mastodon API: Search parameter `following` now correctly returns the followings rather than the followers
+
 ## [2.1.0] - 2020-08-28
 
 ### Changed
index d4fd310690e33f0c7d691f02e90aeb5ebac79ffd..adbef7fb8c45abf7ca989d57f4f4c1bdf1593f6e 100644 (file)
@@ -116,7 +116,7 @@ defmodule Pleroma.User.Search do
   end
 
   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_friends_query(user)
 
   defp filter_invisible_users(query) do
     from(q in query, where: q.invisible == false)
index 559ba59668a057e10c75aec384c2ffeb34fe2d8d..01976bf587f7385f9c9b7c971f37774b52f00d29 100644 (file)
@@ -109,22 +109,22 @@ defmodule Pleroma.UserSearchTest do
                Enum.map(User.search("doe", resolve: false, for_user: u1), & &1.id) == []
     end
 
-    test "finds followers of user by partial name" do
-      u1 = insert(:user)
-      u2 = insert(:user, %{name: "Jimi"})
-      follower_jimi = insert(:user, %{name: "Jimi Hendrix"})
-      follower_lizz = insert(:user, %{name: "Lizz Wright"})
-      friend = insert(:user, %{name: "Jimi"})
-
-      {:ok, follower_jimi} = User.follow(follower_jimi, u1)
-      {:ok, _follower_lizz} = User.follow(follower_lizz, u2)
-      {:ok, u1} = User.follow(u1, friend)
-
-      assert Enum.map(User.search("jimi", following: true, for_user: u1), & &1.id) == [
-               follower_jimi.id
+    test "finds followings of user by partial name" do
+      lizz = insert(:user, %{name: "Lizz"})
+      jimi = insert(:user, %{name: "Jimi"})
+      following_lizz = insert(:user, %{name: "Jimi Hendrix"})
+      following_jimi = insert(:user, %{name: "Lizz Wright"})
+      follower_lizz = insert(:user, %{name: "Jimi"})
+
+      {:ok, lizz} = User.follow(lizz, following_lizz)
+      {:ok, _jimi} = User.follow(jimi, following_jimi)
+      {:ok, _follower_lizz} = User.follow(follower_lizz, lizz)
+
+      assert Enum.map(User.search("jimi", following: true, for_user: lizz), & &1.id) == [
+               following_lizz.id
              ]
 
-      assert User.search("lizz", following: true, for_user: u1) == []
+      assert User.search("lizz", following: true, for_user: lizz) == []
     end
 
     test "find local and remote users for authenticated users" do