diff options
author | Roger Braun <roger@rogerbraun.net> | 2017-10-30 19:23:16 +0100 |
---|---|---|
committer | Roger Braun <roger@rogerbraun.net> | 2017-10-30 19:23:16 +0100 |
commit | 502cb38cd69f9f8c15a0ee597584364f9d36bdf1 (patch) | |
tree | 7f8516e81ff6d1aa188904dab044fec01488bc70 /lib | |
parent | efe12e1a73e13c9e749a4e6cc9c0c8a6988d87db (diff) | |
download | pleroma-502cb38cd69f9f8c15a0ee597584364f9d36bdf1.tar.gz |
Move user search to User module.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/user.ex | 10 | ||||
-rw-r--r-- | lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 17 | ||||
-rw-r--r-- | lib/pleroma/web/router.ex | 2 |
3 files changed, 14 insertions, 15 deletions
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index bfd3a3ad7..bf63a22b3 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -274,4 +274,14 @@ defmodule Pleroma.User do Repo.all(query) end + + def search(query, resolve) do + if resolve do + User.get_or_fetch_by_nickname(query) + end + q = from u in User, + where: fragment("(to_tsvector('english', ?) || to_tsvector('english', ?)) @@ plainto_tsquery('english', ?)", u.nickname, u.name, ^query), + limit: 20 + Repo.all(q) + end end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index dacb0ebe3..9399dee86 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -308,19 +308,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end end - def dousersearch(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do - if params["resolve"] == "true" do - User.get_or_fetch_by_nickname(query) - end - - q = from u in User, - 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) + accounts = User.search(query, params["resolve"] == "true") q = from a in Activity, where: fragment("?->>'type' = 'Create'", a.data), @@ -337,8 +326,8 @@ 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) + def account_search(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do + accounts = User.search(query, params["resolve"] == "true") res = AccountView.render("accounts.json", users: accounts, for: user, as: :user) diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 53f4a45e3..1fb5eadf6 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -55,7 +55,7 @@ defmodule Pleroma.Web.Router do get "/accounts/verify_credentials", MastodonAPIController, :verify_credentials get "/accounts/relationships", MastodonAPIController, :relationships - get "/accounts/search", MastodonAPIController, :accountsearch + get "/accounts/search", MastodonAPIController, :account_search post "/accounts/:id/follow", MastodonAPIController, :follow post "/accounts/:id/unfollow", MastodonAPIController, :unfollow post "/accounts/:id/block", MastodonAPIController, :relationship_noop |