From c992d32afdfaf9c66d8815e2f2e264480eff1274 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 20 Dec 2019 10:23:45 +0100 Subject: [PATCH] Improve algo --- .../detail/composer/TextComposerViewModel.kt | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/composer/TextComposerViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/composer/TextComposerViewModel.kt index 9d6d9aab2e..538d13bb4e 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/composer/TextComposerViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/composer/TextComposerViewModel.kt @@ -102,7 +102,7 @@ class TextComposerViewModel @AssistedInject constructor(@Assisted initialState: users } else { users.filter { - it.displayName?.startsWith(prefix = filter, ignoreCase = true) ?: false + it.displayName?.contains(filter, ignoreCase = true) ?: false } } .sortedBy { it.displayName } @@ -139,11 +139,15 @@ class TextComposerViewModel @AssistedInject constructor(@Assisted initialState: session.rx().liveGroupSummaries(), groupsQueryObservable.throttleLast(300, TimeUnit.MILLISECONDS), BiFunction { groupSummaries, query -> - val filter = query.orNull() ?: "" - groupSummaries - .filter { - it.groupId.contains(filter, ignoreCase = true) - } + val filter = query.orNull() + if (filter.isNullOrBlank()) { + groupSummaries + } else { + groupSummaries + .filter { + it.groupId.contains(filter, ignoreCase = true) + } + } .sortedBy { it.displayName } } ).execute { async ->