From efe12e1a73e13c9e749a4e6cc9c0c8a6988d87db Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 30 Oct 2017 03:37:07 +0000 Subject: [PATCH] Fix /api/v1/accounts/search by splitting account search into its own function --- .../web/mastodon_api/mastodon_api_controller.ex | 14 +++++++++++++- lib/pleroma/web/router.ex | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 971772810..dacb0ebe3 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -308,7 +308,7 @@ def unfollow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do end end - def search(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do + def dousersearch(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do if params["resolve"] == "true" do User.get_or_fetch_by_nickname(query) end @@ -317,6 +317,10 @@ def search(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do where: fragment("(to_tsvector('english', ?) || to_tsvector('english', ?)) @@ plainto_tsquery('english', ?)", u.nickname, u.name, ^query), limit: 20 accounts = Repo.all(q) + end + + def search(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do + accounts = Pleroma.Web.MastodonAPI.MastodonAPIController.dousersearch(conn, params) q = from a in Activity, where: fragment("?->>'type' = 'Create'", a.data), @@ -333,6 +337,14 @@ def search(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do json(conn, res) end + def accountsearch(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do + accounts = Pleroma.Web.MastodonAPI.MastodonAPIController.dousersearch(conn, params) + + res = AccountView.render("accounts.json", users: accounts, for: user, as: :user) + + json(conn, res) + end + def favourites(%{assigns: %{user: user}} = conn, params) do params = conn |> Map.put("type", "Create") diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 45c47eefb..53f4a45e3 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -55,6 +55,7 @@ def user_fetcher(username) do get "/accounts/verify_credentials", MastodonAPIController, :verify_credentials get "/accounts/relationships", MastodonAPIController, :relationships + get "/accounts/search", MastodonAPIController, :accountsearch post "/accounts/:id/follow", MastodonAPIController, :follow post "/accounts/:id/unfollow", MastodonAPIController, :unfollow post "/accounts/:id/block", MastodonAPIController, :relationship_noop