Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
conduwuit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
🥺
conduwuit
Commits
dcac1361
Unverified
Commit
dcac1361
authored
3 years ago
by
Timo Kösters
Browse files
Options
Downloads
Patches
Plain Diff
improvement: /search works for multiple rooms
parent
fee7d3d2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/client_server/search.rs
+40
-13
40 additions, 13 deletions
src/client_server/search.rs
with
40 additions
and
13 deletions
src/client_server/search.rs
+
40
−
13
View file @
dcac1361
...
...
@@ -20,17 +20,32 @@ pub async fn search_events_route(
let
sender_user
=
body
.sender_user
.as_ref
()
.expect
(
"user is authenticated"
);
let
search_criteria
=
body
.search_categories.room_events
.as_ref
()
.unwrap
();
let
filter
=
search_criteria
.filter
.
as_ref
()
.unwrap
();
let
filter
=
search_criteria
.filter
.
clone
()
.unwrap
_or_default
();
let
room_id
=
filter
.rooms
.as_ref
()
.unwrap
()
.first
()
.unwrap
();
let
room_ids
=
filter
.rooms
.clone
()
.unwrap_or_else
(||
{
db
.rooms
.rooms_joined
(
&
sender_user
)
.filter_map
(|
r
|
r
.ok
())
.collect
()
});
let
limit
=
filter
.limit
.map_or
(
10
,
|
l
|
u64
::
from
(
l
)
as
usize
);
if
!
db
.rooms
.is_joined
(
sender_user
,
&
room_id
)
?
{
return
Err
(
Error
::
BadRequest
(
ErrorKind
::
Forbidden
,
"You don't have permission to view this room."
,
));
let
mut
searches
=
Vec
::
new
();
for
room_id
in
room_ids
{
if
!
db
.rooms
.is_joined
(
sender_user
,
&
room_id
)
?
{
return
Err
(
Error
::
BadRequest
(
ErrorKind
::
Forbidden
,
"You don't have permission to view this room."
,
));
}
let
search
=
db
.rooms
.search_pdus
(
&
room_id
,
&
search_criteria
.search_term
)
?
;
searches
.push
(
search
.0
.peekable
());
}
let
skip
=
match
body
.next_batch
.as_ref
()
.map
(|
s
|
s
.parse
())
{
...
...
@@ -44,12 +59,20 @@ pub async fn search_events_route(
None
=>
0
,
// Default to the start
};
let
search
=
db
.rooms
.search_pdus
(
&
room_id
,
&
search_criteria
.search_term
)
?
;
let
mut
results
=
Vec
::
new
();
for
_
in
0
..
skip
+
limit
{
if
let
Some
(
s
)
=
searches
.iter_mut
()
.map
(|
s
|
(
s
.peek
()
.cloned
(),
s
))
.max_by_key
(|(
peek
,
_
)|
peek
.clone
())
.and_then
(|(
_
,
i
)|
i
.next
())
{
results
.push
(
s
);
}
}
let
results
=
search
.
0
let
results
=
results
.
iter
()
.map
(|
result
|
{
Ok
::
<
_
,
Error
>
(
SearchResult
{
context
:
EventContextResult
{
...
...
@@ -84,7 +107,11 @@ pub async fn search_events_route(
next_batch
,
results
,
state
:
BTreeMap
::
new
(),
// TODO
highlights
:
search
.1
,
highlights
:
search_criteria
.search_term
.split_terminator
(|
c
:
char
|
!
c
.is_alphanumeric
())
.map
(
str
::
to_lowercase
)
.collect
::
<
Vec
<
_
>>
(),
},
})
.into
())
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment