Search for rooms closure as a separate variable.
continuous-integration/drone/pr Build is passing Details
continuous-integration/drone/push Build is passing Details

This commit is contained in:
projectmoon 2021-05-28 21:19:26 +00:00
parent 7f0bdc1e82
commit 0c0ddafd03
1 changed files with 11 additions and 9 deletions

View File

@ -40,19 +40,21 @@ impl Fuseable for RoomNameAndId {
/// returned, or None if no matches were found. /// returned, or None if no matches were found.
fn search_for_room<'a>( fn search_for_room<'a>(
rooms_for_user: &'a [RoomNameAndId], rooms_for_user: &'a [RoomNameAndId],
query: &str, search_for: &str,
) -> Option<&'a RoomNameAndId> { ) -> Option<&'a RoomNameAndId> {
//Lowest score is the best match. //Lowest score is the best match.
rooms_for_user let best_fuzzy_match = || -> Option<&RoomNameAndId> {
.iter()
.find(|room| room.id == query)
.or_else(|| {
Fuse::default() Fuse::default()
.search_text_in_fuse_list(query, &rooms_for_user) .search_text_in_fuse_list(search_for, &rooms_for_user)
.into_iter() .into_iter()
.min_by(|r1, r2| r1.score.partial_cmp(&r2.score).unwrap()) .min_by(|r1, r2| r1.score.partial_cmp(&r2.score).unwrap())
.and_then(|result| rooms_for_user.get(result.index)) .and_then(|result| rooms_for_user.get(result.index))
}) };
rooms_for_user
.iter()
.find(|room| room.id == search_for)
.or_else(best_fuzzy_match)
} }
async fn get_rooms_for_user( async fn get_rooms_for_user(