Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
502cb38c
Commit
502cb38c
authored
Oct 30, 2017
by
lain
Browse files
Move user search to User module.
parent
efe12e1a
Changes
4
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/user.ex
View file @
502cb38c
...
...
@@ -274,4 +274,14 @@ def get_notified_from_activity(%Activity{data: %{"to" => to}} = activity) 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
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
View file @
502cb38c
...
...
@@ -308,19 +308,8 @@ def unfollow(%{assigns: %{user: follower}} = conn, %{"id" => id}) 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
.
douser
search
(
conn
,
params
)
accounts
=
User
.
search
(
query
,
params
[
"resolve"
]
==
"true"
)
q
=
from
a
in
Activity
,
where:
fragment
(
"?->>'type' = 'Create'"
,
a
.
data
),
...
...
@@ -337,8 +326,8 @@ 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
.
douser
search
(
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
)
...
...
lib/pleroma/web/router.ex
View file @
502cb38c
...
...
@@ -55,7 +55,7 @@ def user_fetcher(username) 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
...
...
test/web/mastodon_api/mastodon_api_controller_test.exs
View file @
502cb38c
...
...
@@ -319,6 +319,19 @@ test "unimplemented mutes, follow_requests, blocks, domain blocks" do
end
)
end
test
"account seach"
,
%{
conn:
conn
}
do
user
=
insert
(
:user
)
user_two
=
insert
(
:user
,
%{
nickname:
"shp@shitposter.club"
})
user_three
=
insert
(
:user
,
%{
nickname:
"shp@heldscal.la"
,
name:
"I love 2hu"
})
conn
=
conn
|>
assign
(
:user
,
user
)
|>
get
(
"/api/v1/accounts/search"
,
%{
"q"
=>
"2hu"
})
assert
[
account
]
=
json_response
(
conn
,
200
)
assert
account
[
"id"
]
==
user_three
.
id
end
test
"search"
,
%{
conn:
conn
}
do
user
=
insert
(
:user
)
user_two
=
insert
(
:user
,
%{
nickname:
"shp@shitposter.club"
})
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment