mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-23 16:40:29 +00:00
Fix /api/v1/accounts/search by splitting account search into its own function
This commit is contained in:
parent
9168497f8f
commit
efe12e1a73
2 changed files with 14 additions and 1 deletions
|
@ -308,7 +308,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController 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 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController 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 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController 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 @@ defmodule Pleroma.Web.Router 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
|
||||
|
|
Loading…
Reference in a new issue