diff --git a/ViewModels/Sources/ViewModels/AddIdentityViewModel.swift b/ViewModels/Sources/ViewModels/AddIdentityViewModel.swift index 48aa697..939cf08 100644 --- a/ViewModels/Sources/ViewModels/AddIdentityViewModel.swift +++ b/ViewModels/Sources/ViewModels/AddIdentityViewModel.swift @@ -27,7 +27,7 @@ public final class AddIdentityViewModel: ObservableObject { self.instanceURLService = instanceURLService let url = $urlFieldText - .debounce(for: 0.5, scheduler: DispatchQueue.global()) + .debounce(for: .seconds(Self.textFieldDebounceInterval), scheduler: DispatchQueue.global()) .removeDuplicates() .flatMap { instanceURLService.url(text: $0).publisher @@ -86,6 +86,7 @@ public extension AddIdentityViewModel { } private extension AddIdentityViewModel { + private static let textFieldDebounceInterval: TimeInterval = 0.5 func addIdentity(kind: AllIdentitiesService.IdentityCreation) { instanceURLService.url(text: urlFieldText).publisher .map { ($0, kind) } diff --git a/ViewModels/Sources/ViewModels/CollectionItemsViewModel.swift b/ViewModels/Sources/ViewModels/CollectionItemsViewModel.swift index 0efe066..f90e814 100644 --- a/ViewModels/Sources/ViewModels/CollectionItemsViewModel.swift +++ b/ViewModels/Sources/ViewModels/CollectionItemsViewModel.swift @@ -49,7 +49,7 @@ public final class CollectionItemsViewModel: ObservableObject { identification.appPreferences.positionBehavior(markerTimeline: markerTimeline) == .rememberPosition lastReadId.compactMap { $0 } .removeDuplicates() - .debounce(for: 0.5, scheduler: DispatchQueue.global()) + .debounce(for: .seconds(Self.lastReadIdDebounceInterval), scheduler: DispatchQueue.global()) .flatMap { identification.service.setLastReadId($0, forMarker: markerTimeline) } .sink { _ in } receiveValue: { _ in } .store(in: &cancellables) @@ -283,6 +283,8 @@ extension CollectionItemsViewModel: CollectionViewModel { } private extension CollectionItemsViewModel { + private static let lastReadIdDebounceInterval: TimeInterval = 0.5 + var lastUpdateWasContextParentOnly: Bool { collectionService is ContextService && lastUpdate.items.map(\.count) == [0, 1, 0] }