From: Roger Braun Date: Sat, 16 Sep 2017 09:26:20 +0000 (+0200) Subject: Add remote user fetching to search. X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=c36229c4aa3bd0ac49d9dcd589790f5c47470564;p=akkoma Add remote user fetching to search. --- diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index fcc87d414..c231ff7f8 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -287,7 +287,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end end - def search(%{assigns: %{user: user}} = conn, %{"q" => query}) do + def search(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do + if params["resolve"] == "true" do + User.get_or_fetch_by_nickname(query) + end + q = from u in User, where: fragment("(to_tsvector('english', ?) || to_tsvector('english', ?)) @@ plainto_tsquery('english', ?)", u.nickname, u.name, ^query), limit: 20 diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 1bef1a1fd..4261ac6b1 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -332,4 +332,13 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do [status] = results["statuses"] assert status["id"] == activity.id end + + test "search fetches remote accounts", %{conn: conn} do + conn = conn + |> get("/api/v1/search", %{"q" => "shp@social.heldscal.la", "resolve" => "true"}) + + assert results = json_response(conn, 200) + [account] = results["accounts"] + assert account["acct"] == "shp@social.heldscal.la" + end end