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
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")

View File

@ -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