Skip to content
Snippets Groups Projects
Commit fabd8099 authored by Dariusz Rybicki's avatar Dariusz Rybicki
Browse files

Perform search using background scheduler

parent 71123aab
No related branches found
No related tags found
1 merge request!98Fix invitation deep link handling
...@@ -89,60 +89,60 @@ final class SearchLeftViewModel { ...@@ -89,60 +89,60 @@ final class SearchLeftViewModel {
func didStartSearching() { func didStartSearching() {
guard stateSubject.value.input.isEmpty == false else { return } guard stateSubject.value.input.isEmpty == false else { return }
hudManager.show(.init( backgroundScheduler.schedule { [weak self] in
actionTitle: Localized.Ud.Search.cancel, guard let self else { return }
hasDotAnimation: true,
isAutoDismissable: false,
onTapClosure: { [weak self] in
guard let self else { return }
self.didTapCancelSearch()
}
))
var content = stateSubject.value.input
if stateSubject.value.item == .phone {
content += stateSubject.value.country.code
}
enum NodeRegistrationError: Error { self.hudManager.show(.init(
case unhealthyNet actionTitle: Localized.Ud.Search.cancel,
case belowMinimum hasDotAnimation: true,
} isAutoDismissable: false,
onTapClosure: { [weak self] in
guard let self else { return }
self.didTapCancelSearch()
}
))
retry(max: 5, retryStrategy: .delay(seconds: 2)) { [weak self] in var content = self.stateSubject.value.input
guard let self else { return }
do { if self.stateSubject.value.item == .phone {
let nrr = try self.messenger.cMix.get()!.getNodeRegistrationStatus() content += self.stateSubject.value.country.code
if nrr.ratio < 0.8 { throw NodeRegistrationError.belowMinimum }
} catch {
throw NodeRegistrationError.unhealthyNet
} }
}.finalCatch { [weak self] in
guard let self else { return }
if case .unhealthyNet = $0 as? NodeRegistrationError { enum NodeRegistrationError: Error {
self.hudManager.show(.init(content: "Network is not healthy yet, try again within the next minute or so.")) case unhealthyNet
} else if case .belowMinimum = $0 as? NodeRegistrationError { case belowMinimum
self.hudManager.show(.init(content:"Node registration ratio is still below 80%, try again within the next minute or so."))
} else {
self.hudManager.show(.init(error: $0))
} }
return retry(max: 5, retryStrategy: .delay(seconds: 2)) { [weak self] in
} guard let self else { return }
var factType: FactType = .username do {
let nrr = try self.messenger.cMix.get()!.getNodeRegistrationStatus()
if nrr.ratio < 0.8 { throw NodeRegistrationError.belowMinimum }
} catch {
throw NodeRegistrationError.unhealthyNet
}
}.finalCatch { [weak self] in
guard let self else { return }
if stateSubject.value.item == .phone { if case .unhealthyNet = $0 as? NodeRegistrationError {
factType = .phone self.hudManager.show(.init(content: "Network is not healthy yet, try again within the next minute or so."))
} else if stateSubject.value.item == .email { } else if case .belowMinimum = $0 as? NodeRegistrationError {
factType = .email self.hudManager.show(.init(content:"Node registration ratio is still below 80%, try again within the next minute or so."))
} } else {
self.hudManager.show(.init(error: $0))
}
backgroundScheduler.schedule { [weak self] in return
guard let self else { return } }
var factType: FactType = .username
if self.stateSubject.value.item == .phone {
factType = .phone
} else if self.stateSubject.value.item == .email {
factType = .email
}
do { do {
let report = try SearchUD.live( let report = try SearchUD.live(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment