Merge branch 'feature/pleromafe-usersearch' into 'develop'
Add Twitter / Pleroma API user search See merge request pleroma/pleroma!452
This commit is contained in:
commit
2f639ea129
5 changed files with 42 additions and 2 deletions
|
|
@ -498,7 +498,7 @@ defmodule Pleroma.User do
|
|||
Repo.all(query)
|
||||
end
|
||||
|
||||
def search(query, resolve) do
|
||||
def search(query, resolve \\ false) do
|
||||
# strip the beginning @ off if there is a query
|
||||
query = String.trim_leading(query, "@")
|
||||
|
||||
|
|
|
|||
|
|
@ -250,7 +250,12 @@ defmodule Pleroma.Web.Router do
|
|||
get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
|
||||
end
|
||||
|
||||
scope "/api", Pleroma.Web do
|
||||
scope "/api", Pleroma.Web, as: :twitter_api_search do
|
||||
pipe_through(:api)
|
||||
get("/pleroma/search_user", TwitterAPI.Controller, :search_user)
|
||||
end
|
||||
|
||||
scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
|
||||
pipe_through(:authenticated_api)
|
||||
|
||||
get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
|
||||
|
|
|
|||
|
|
@ -529,6 +529,13 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|
|||
|> render(ActivityView, "index.json", %{activities: activities, for: user})
|
||||
end
|
||||
|
||||
def search_user(%{assigns: %{user: user}} = conn, %{"query" => query}) do
|
||||
users = User.search(query, true)
|
||||
|
||||
conn
|
||||
|> render(UserView, "index.json", %{users: users, for: user})
|
||||
end
|
||||
|
||||
defp bad_request_reply(conn, error_message) do
|
||||
json = error_json(conn, error_message)
|
||||
json_reply(conn, 400, json)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue