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()
|
.eraseToAnyPublisher()
|
||||||
}
|
}
|
||||||
|
|
||||||
func isPublicTimelineAvailable(url: URL) -> AnyPublisher<Bool, Never> {
|
func isPublicTimelineAvailable(url: URL) -> AnyPublisher<Bool, Error> {
|
||||||
httpClient.request(
|
httpClient.request(
|
||||||
MastodonAPITarget(
|
MastodonAPITarget(
|
||||||
baseURL: url,
|
baseURL: url,
|
||||||
endpoint: TimelinesEndpoint.public(local: true),
|
endpoint: TimelinesEndpoint.public(local: true),
|
||||||
accessToken: nil))
|
accessToken: nil))
|
||||||
.map { _ in true }
|
.map { _ in true }
|
||||||
.catch { _ in Just(false) }
|
|
||||||
.eraseToAnyPublisher()
|
.eraseToAnyPublisher()
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateFilter() -> AnyPublisher<Never, Never> {
|
func updateFilter() -> AnyPublisher<Never, Error> {
|
||||||
httpClient.request(UpdatedFilterTarget())
|
httpClient.request(UpdatedFilterTarget())
|
||||||
.handleEvents(receiveOutput: { userDefaultsClient.updatedInstanceFilter = $0 })
|
.handleEvents(receiveOutput: { userDefaultsClient.updatedInstanceFilter = $0 })
|
||||||
.map { _ in () }
|
|
||||||
.replaceError(with: ())
|
|
||||||
.ignoreOutput()
|
.ignoreOutput()
|
||||||
.eraseToAnyPublisher()
|
.eraseToAnyPublisher()
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ public extension AddIdentityViewModel {
|
||||||
|
|
||||||
func refreshFilter() {
|
func refreshFilter() {
|
||||||
instanceURLService.updateFilter()
|
instanceURLService.updateFilter()
|
||||||
.sink { _ in }
|
.sink { _ in } receiveValue: { _ in }
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,12 +61,6 @@ private extension AddIdentityViewModel {
|
||||||
|
|
||||||
url.receive(on: DispatchQueue.main).assign(to: &$url)
|
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
|
url.flatMap { [weak self] url -> AnyPublisher<Instance?, Never> in
|
||||||
guard let self = self, let url = url else {
|
guard let self = self, let url = url else {
|
||||||
return Just(nil).eraseToAnyPublisher()
|
return Just(nil).eraseToAnyPublisher()
|
||||||
|
@ -79,6 +73,18 @@ private extension AddIdentityViewModel {
|
||||||
}
|
}
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
.assign(to: &$instance)
|
.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) {
|
func addIdentity(authenticated: Bool) {
|
||||||
|
|
Loading…
Reference in a new issue