improvement: filter our room directory

Fixes #35
This commit is contained in:
Timo Kösters 2021-06-14 11:24:32 +02:00
parent 01e01bf25e
commit 77a23f8969
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4

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<_>>();