diff --git a/ServiceLayer/Sources/ServiceLayer/Services/InstanceURLService.swift b/ServiceLayer/Sources/ServiceLayer/Services/InstanceURLService.swift index bef62cc..8f8747f 100644 --- a/ServiceLayer/Sources/ServiceLayer/Services/InstanceURLService.swift +++ b/ServiceLayer/Sources/ServiceLayer/Services/InstanceURLService.swift @@ -47,22 +47,19 @@ public extension InstanceURLService { .eraseToAnyPublisher() } - func isPublicTimelineAvailable(url: URL) -> AnyPublisher { + func isPublicTimelineAvailable(url: URL) -> AnyPublisher { httpClient.request( MastodonAPITarget( baseURL: url, endpoint: TimelinesEndpoint.public(local: true), accessToken: nil)) .map { _ in true } - .catch { _ in Just(false) } .eraseToAnyPublisher() } - func updateFilter() -> AnyPublisher { + func updateFilter() -> AnyPublisher { httpClient.request(UpdatedFilterTarget()) .handleEvents(receiveOutput: { userDefaultsClient.updatedInstanceFilter = $0 }) - .map { _ in () } - .replaceError(with: ()) .ignoreOutput() .eraseToAnyPublisher() } diff --git a/ViewModels/Sources/ViewModels/AddIdentityViewModel.swift b/ViewModels/Sources/ViewModels/AddIdentityViewModel.swift index 98ac9f3..b62b74b 100644 --- a/ViewModels/Sources/ViewModels/AddIdentityViewModel.swift +++ b/ViewModels/Sources/ViewModels/AddIdentityViewModel.swift @@ -42,7 +42,7 @@ public extension AddIdentityViewModel { func refreshFilter() { instanceURLService.updateFilter() - .sink { _ in } + .sink { _ in } receiveValue: { _ in } .store(in: &cancellables) } @@ -61,12 +61,6 @@ private extension AddIdentityViewModel { url.receive(on: DispatchQueue.main).assign(to: &$url) - url.compactMap { $0 } - .flatMap(instanceURLService.isPublicTimelineAvailable(url:)) - .replaceError(with: false) - .receive(on: DispatchQueue.main) - .assign(to: &$isPublicTimelineAvailable) - url.flatMap { [weak self] url -> AnyPublisher in guard let self = self, let url = url else { return Just(nil).eraseToAnyPublisher() @@ -79,6 +73,18 @@ private extension AddIdentityViewModel { } .receive(on: DispatchQueue.main) .assign(to: &$instance) + + url.flatMap { [weak self] url -> AnyPublisher in + guard let self = self, let url = url else { + return Just(false).eraseToAnyPublisher() + } + + return self.instanceURLService.isPublicTimelineAvailable(url: url) + .replaceError(with: false) + .eraseToAnyPublisher() + } + .receive(on: DispatchQueue.main) + .assign(to: &$isPublicTimelineAvailable) } func addIdentity(authenticated: Bool) {