mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-25 17:50:59 +00:00
Refactoring
This commit is contained in:
parent
d061d17cb7
commit
5927d5f27a
2 changed files with 15 additions and 12 deletions
|
@ -47,22 +47,19 @@ public extension InstanceURLService {
|
|||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
func isPublicTimelineAvailable(url: URL) -> AnyPublisher<Bool, Never> {
|
||||
func isPublicTimelineAvailable(url: URL) -> AnyPublisher<Bool, Error> {
|
||||
httpClient.request(
|
||||
MastodonAPITarget(
|
||||
baseURL: url,
|
||||
endpoint: TimelinesEndpoint.public(local: true),
|
||||
accessToken: nil))
|
||||
.map { _ in true }
|
||||
.catch { _ in Just(false) }
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
func updateFilter() -> AnyPublisher<Never, Never> {
|
||||
func updateFilter() -> AnyPublisher<Never, Error> {
|
||||
httpClient.request(UpdatedFilterTarget())
|
||||
.handleEvents(receiveOutput: { userDefaultsClient.updatedInstanceFilter = $0 })
|
||||
.map { _ in () }
|
||||
.replaceError(with: ())
|
||||
.ignoreOutput()
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
|
|
@ -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<Instance?, Never> 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<Bool, Never> 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) {
|
||||
|
|
Loading…
Reference in a new issue