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

This commit is contained in:
Mark Felder 2017-10-30 03:37:07 +00:00
parent 9168497f8f
commit efe12e1a73
2 changed files with 14 additions and 1 deletions

View File

@ -308,7 +308,7 @@ def unfollow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
end end
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 if params["resolve"] == "true" do
User.get_or_fetch_by_nickname(query) User.get_or_fetch_by_nickname(query)
end 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), where: fragment("(to_tsvector('english', ?) || to_tsvector('english', ?)) @@ plainto_tsquery('english', ?)", u.nickname, u.name, ^query),
limit: 20 limit: 20
accounts = Repo.all(q) 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, q = from a in Activity,
where: fragment("?->>'type' = 'Create'", a.data), where: fragment("?->>'type' = 'Create'", a.data),
@ -333,6 +337,14 @@ def search(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do
json(conn, res) json(conn, res)
end 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 def favourites(%{assigns: %{user: user}} = conn, params) do
params = conn params = conn
|> Map.put("type", "Create") |> Map.put("type", "Create")

View File

@ -55,6 +55,7 @@ def user_fetcher(username) do
get "/accounts/verify_credentials", MastodonAPIController, :verify_credentials get "/accounts/verify_credentials", MastodonAPIController, :verify_credentials
get "/accounts/relationships", MastodonAPIController, :relationships get "/accounts/relationships", MastodonAPIController, :relationships
get "/accounts/search", MastodonAPIController, :accountsearch
post "/accounts/:id/follow", MastodonAPIController, :follow post "/accounts/:id/follow", MastodonAPIController, :follow
post "/accounts/:id/unfollow", MastodonAPIController, :unfollow post "/accounts/:id/unfollow", MastodonAPIController, :unfollow
post "/accounts/:id/block", MastodonAPIController, :relationship_noop post "/accounts/:id/block", MastodonAPIController, :relationship_noop