Commit efe12e1a authored by feld's avatar feld
Browse files

Fix /api/v1/accounts/search by splitting account search into its own function

parent 9168497f
......@@ -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")
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment