mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-05 11:58:32 +00:00
Fix Suggestion Pattern when text is empty (#1943)
* fix + debounce improvement * comment * improved existing function to be more generic
This commit is contained in:
@@ -55,8 +55,10 @@ final class CompletionSuggestionService: CompletionSuggestionServiceProtocol {
|
||||
return membersSuggestion
|
||||
}
|
||||
}
|
||||
.debounce(for: 0.5, scheduler: DispatchQueue.main)
|
||||
.eraseToAnyPublisher()
|
||||
// We only debounce if the suggestion is nil
|
||||
.debounceAndRemoveDuplicates(on: DispatchQueue.main) { [weak self] _ in
|
||||
self?.suggestionTriggerSubject.value != nil ? .milliseconds(500) : .milliseconds(0)
|
||||
}
|
||||
|
||||
Task {
|
||||
switch await roomProxy.canUserTriggerRoomNotification(userID: roomProxy.ownUserID) {
|
||||
@@ -73,6 +75,10 @@ final class CompletionSuggestionService: CompletionSuggestionServiceProtocol {
|
||||
}
|
||||
|
||||
private static func isIncluded(searchText: String, userID: String, displayName: String?) -> Bool {
|
||||
// If the search text is empty give back all the results
|
||||
guard !searchText.isEmpty else {
|
||||
return true
|
||||
}
|
||||
let containedInUserID = userID.localizedStandardContains(searchText.lowercased())
|
||||
|
||||
let containedInDisplayName: Bool
|
||||
|
||||
@@ -95,7 +95,7 @@ class InviteUsersScreenViewModel: InviteUsersScreenViewModelType, InviteUsersScr
|
||||
private func setupSubscriptions(selectedUsers: CurrentValuePublisher<[UserProfileProxy], Never>) {
|
||||
context.$viewState
|
||||
.map(\.bindings.searchQuery)
|
||||
.debounceAndRemoveDuplicates()
|
||||
.debounceTextQueriesAndRemoveDuplicates()
|
||||
.sink { [weak self] _ in
|
||||
self?.fetchUsers()
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ class StartChatScreenViewModel: StartChatScreenViewModelType, StartChatScreenVie
|
||||
private func setupBindings() {
|
||||
context.$viewState
|
||||
.map(\.bindings.searchQuery)
|
||||
.debounceAndRemoveDuplicates()
|
||||
.debounceTextQueriesAndRemoveDuplicates()
|
||||
.sink { [weak self] _ in
|
||||
self?.fetchUsers()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user