Merge branch 'roomdirfilter' into 'master'

improvement: filter our room directory

Closes #35

See merge request famedly/conduit!102
This commit is contained in:
Timo Kösters 2021-06-14 09:33:20 +00:00
commit 07271b7725
1 changed files with 30 additions and 0 deletions

View File

@ -315,6 +315,36 @@ pub async fn get_public_rooms_filtered_helper(
Ok(chunk)
})
.filter_map(|r: Result<_>| r.ok()) // Filter out buggy rooms
.filter(|chunk| {
if let Some(query) = filter
.generic_search_term
.as_ref()
.map(|q| q.to_lowercase())
{
if let Some(name) = &chunk.name {
if name.to_lowercase().contains(&query) {
return true;
}
}
if let Some(topic) = &chunk.topic {
if topic.to_lowercase().contains(&query) {
return true;
}
}
if let Some(canonical_alias) = &chunk.canonical_alias {
if canonical_alias.as_str().to_lowercase().contains(&query) {
return true;
}
}
false
} else {
// No search term
true
}
})
// We need to collect all, so we can sort by member count
.collect::<Vec<_>>();